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
CPP: Add query for CWE-20 Improper Input Validation #5326
Conversation
This query reminds me of cpp/late-negative-test, which checks for a test that i < 0 (or i >= 0 etc) after accessing an array using i as the index. Your query instead looks at calls to standard functions such as memcpy - and is implemented using more up-to-date libraries than cpp/late-negative-test. Seems promising.
I've made a few comments on the QL, but I haven't tried out the query for myself yet. I'm curious to see whether we get a lot of false positives on reference parameters for example.
I appreciate the qhelp, example and test as always.
cpp/ql/src/experimental/Security/CWE/CWE-020/LateCheckOfFunctionArgument.ql
Outdated
Show resolved
Hide resolved
cpp/ql/src/experimental/Security/CWE/CWE-020/LateCheckOfFunctionArgument.ql
Outdated
Show resolved
Hide resolved
cpp/ql/src/experimental/Security/CWE/CWE-020/LateCheckOfFunctionArgument.ql
Outdated
Show resolved
Hide resolved
cpp/ql/src/experimental/Security/CWE/CWE-020/LateCheckOfFunctionArgument.ql
Outdated
Show resolved
Hide resolved
good day. you are absolutely correct about but in the process of creating the request, I noticed that you already have a working implementation. |
cpp/ql/src/experimental/Security/CWE/CWE-020/LateCheckOfFunctionArgument.ql
Outdated
Show resolved
Hide resolved
cpp/ql/src/experimental/Security/CWE/CWE-020/LateCheckOfFunctionArgument.ql
Outdated
Show resolved
Hide resolved
Co-authored-by: Geoffrey White <[email protected]>
|
A sample of results on LGTM: https://lgtm.com/query/4397987357482832096/ I didn't find any issues with reference parameters, but I think quite a high proportion of the results are false positives - or at least, they don't really resemble the intent of the query. I'm not sure what to suggest but I'll wait and see if you have any ideas? Failing that I'm happy to merge this into experimental so others can try it out and maybe improve it. |
|
thanks for the active work with the request. I have looked at your selection of results and am ready to discuss any of them. I like them all, I really wanted to find them. regarding reference variables, this is an interesting observation. perhaps this is due to the desire to control the argument by value. and unfortunately I cannot yet imagine the use of controlled arguments by reference, if it's not difficult for you, write a fake example so that I could think more deeply. |
|
Some test failures:
Regarding false positives, lets take a look at the result on I don't think this check (assuming it's the one the query has identified) is checking that there is room in the buffer, it appears to be part of preparing for the next step of whatever it is the code is doing. So it's fine that it occurs after the call to |
thank.
in this example, I see that on line 573, the developer thinks it is possible that to be absolutely strict, then 2 and 3 points are |
I think this is the most likely case, and the claim that line 573 should be I agree that if 1. is true, the issue is much more serious. In any case I'll merge this query once the tests pass. Happy to discuss further and review follow-up pull requests. |
|
i corrected the test. and did the formatting. |
Good day.
This error is pretty simple. Checking the value of the buffer length occurs after calling the function to work with it.
The error is quite common in projects and requires the attention of the developer.
It should be noted that most often an error occurs as a result of code refactoring.
Information about the found and accepted fix in the project: irssi/irssi#1270