-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
code scanning alert in generated code #125
Comments
Hi @dhivyasa, thanks for reporting this. I'll have a closer look at this tomorrow. I'm almost sure this is a false positive. I don't even quite get what the scanner tries to flag 🙂. Again, I'll have a closer look tomorrow. |
@dhivyasa I had a closer look at this, specifically trying to figure out what codeQL is doing here. I must admit, it's not clear why it would flag this as an off-by-one. The examples do not relate to the actual code you pasted here and the code is also correct in what it's doing. Maybe CodeQL gets somehow confused by the fact that this is generated code and for that reason there are a lot of hardcoded indices. Does this answer your question? |
Closing due to inactivity. Please re-open, if needed. |
Hey @petergtz 👋, I am running into this as well. Take the following generated code snippet for example: func (c *MockService_MethodName_OngoingVerification) GetAllCapturedArguments() (_param0 []context.Context, _param1 []*models.ModelName) {
params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations)
if len(params) > 0 {
Dismissed
_param0 = make([]context.Context, len(c.methodInvocations))
for u, param := range params[0] {
_param0[u] = param.(context.Context)
}
_param1 = make([]*models.ModelName, len(c.methodInvocations))
for u, param := range params[1] {
_param1[u] = param.(*models.ModelName)
}
}
return
} I believe the CodeQL error is complaining since technically the |
Thanks for shedding light on this @AndrewRPorter. I understand it now. I think CodeQL is still wrong and the code is correct. Do you happen to know if we can add a suppression comment to avoid this false positive? Alternatively, we could change the comparison to Fancy submitting a PR? |
I am able to suppress the alert as "used in tests" but for some larger mocks this can be an annoying processing suppressing many alerts.
Can you help me understand why you think this? I see the following cases,
I'm happy to help contribute a fix |
What I meant here, was: make a code change in Pegomock to generate code that tells CodeQL to ignore this. Python's flake8 linter (and others allows this via
There are only 2 cases:
Lines 352 to 373 in dcebf66
That knowledge cannot be seen in the generated code and therefore CodeQL cannot know it. CodeQL here is really not useful. |
Thanks for explaining! Unfortunately it looks like CodeQL does not support inline suppressions right now: github/codeql#11427. |
Addressed by #126. Closing this issue. |
The generated mock code trigged off by one error in a code scanning utility, codeQL
https://github.com/github/codeql/blob/78fcbd07d654881d9d3395efc0ea371c392529de/go/ql/src/InconsistentCode/LengthComparisonOffByOn
The check for len of params triggered it. Not sure if it is a false positive or there is abetter way to do this other than using indexes.
This happened on Tracer package. Also I think all generated code follow similar pattern
pegomock generate"go.opentelemetry.io/otel/trace" Tracer
The text was updated successfully, but these errors were encountered: