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-401 memory leak on unsuccessful call to realloc function #4881
Conversation
Some initial thoughts:
- this query looks promising, and is certainly capable of finding genuine issues that our existing memory queries (in particular
cpp/memory-never-freedandcpp/memory-may-not-be-freed) do not.👍 - the tests are fairly thorough.
👍 - I've made quite a few suggestions; feel free to pick and choose what you think is most important, and ask for help if you need it.
cpp/ql/src/experimental/Security/CWE/CWE-401/MemoryLeakOnFailedCallToRealloc.qhelp
Outdated
Show resolved
Hide resolved
cpp/ql/src/experimental/Security/CWE/CWE-401/MemoryLeakOnFailedCallToRealloc.qhelp
Outdated
Show resolved
Hide resolved
cpp/ql/src/experimental/Security/CWE/CWE-401/MemoryLeakOnFailedCallToRealloc.ql
Outdated
Show resolved
Hide resolved
cpp/ql/src/experimental/Security/CWE/CWE-401/MemoryLeakOnFailedCallToRealloc.ql
Outdated
Show resolved
Hide resolved
cpp/ql/test/experimental/query-tests/Security/CWE/CWE-401/semmle/tests/test.c
Show resolved
Hide resolved
cpp/ql/src/experimental/Security/CWE/CWE-401/MemoryLeakOnFailedCallToRealloc.ql
Show resolved
Hide resolved
cpp/ql/src/experimental/Security/CWE/CWE-401/MemoryLeakOnFailedCallToRealloc.ql
Outdated
Show resolved
Hide resolved
cpp/ql/src/experimental/Security/CWE/CWE-401/MemoryLeakOnFailedCallToRealloc.ql
Outdated
Show resolved
Hide resolved
cpp/ql/src/experimental/Security/CWE/CWE-401/MemoryLeakOnFailedCallToRealloc.ql
Outdated
Show resolved
Hide resolved
|
Thank you for such a large number of adjustments, I will try to fix them promptly. |
…dCallToRealloc.qhelp Co-authored-by: Geoffrey White <40627776+geoffw0@users.noreply.github.com>
…dCallToRealloc.qhelp Co-authored-by: Geoffrey White <40627776+geoffw0@users.noreply.github.com>
…dCallToRealloc.ql Co-authored-by: Geoffrey White <40627776+geoffw0@users.noreply.github.com>
|
good day. |
I thought since there is no work on this PR, I will delete the residual import.
sorry i was in a hurry
sorry i was in a hurry
sorry i was in a hurry
sorry i was in a hurry
sorry i was in a hurry
sorry i was in a hurry
|
Hi, thanks for the changes and thank you for your contribution. Results look promising, it certainly finds some issues! I think there are still some improvements to be made, but I intend merge this (once the checks pass) and then try some tweaks myself. Maybe get that false positive rate down a bit more. |
|
please tell me. |
|
We think it's probably a good idea to make the application now with the query in its current state, as my follow-up changes won't factor into the evaluation anyway. The checks have passed so I'm merging this now. |
|
I have two suggestions:
|
|
Apologies, that was a bad example above. |
|
I already have a solution to issue 1, I will make a PR for it now so that we don't end up with merge issues. I was not aware of issue 2 so that's something you could look into. |
|
thanks for your comment. regarding problem 2, I found such calls to be extremely rare (at least on my test set of projects). |
|
My suggested changes for 1: #4979 |
|
I don't really understand my role in said discussion. so I immediately apologize if I write something superfluous. regarding @geoffw0's suggested change. I once again apologize if my words were not useful here. |
|
in more detail regarding problem 2. as I wrote above, I did not set myself the goal of tracking these situations, if you consider them critical, I will certainly supplement the detection with this check. but I want to draw your attention that there are several types of vulnerable use of realloc that will not be detected by my request. at the same time, I consider them quite rare. at present, when such a mistake is widely presented, I would not want to complicate the query. as an example I can give the expression a = b = realloc (a, n) which is also not detected. but I do not have enough experience to say something, so I ask you to tell me more specifically what I should do in this situation. Thank you. |
I don't think these are special cases, they are all functions which return.
Yes, it looks for any program termination in the same function as the |
|
I want you to understand me correctly, I'm new to your system. plus not a native speaker. so if my words seem stupid, then I apologize for the time spent on them.
maybe I'm wrong, in this matter I need time. I will try to make a test demonstrating this problem. but for example, in the
this is very reasonable, but only for the main (base) set of queries. at the same time, I would like to clarify my next steps with this request. can he still qualify for the reward or the above errors and your change will revoke this right? What other actions would be helpful on my part? |
I see what you mean,
I'm not familiar with the process, but my understanding is that you will qualify based on the version before my change, and possibly contributions you make afterwards as well (but I'm not sure on the bit). |
|
I wrote my vision in PR, I remind you that I could be wrong. at the same time I would like to ask you to prompt me for a similar script to estimate the running time of a predicate. |
I usually run queries locally when I want to examine running times and performance. In CodeQL for Visual Studio Code you can see run times and access logs from the query history window. This can also be done with command line tools. However query optimization is a complicated and often counterintuitive subject, and the QL optimizer usually does an excellent job automatically. Do you have any concerns for this query? |

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

Good day.
This is my second request. I am grateful for @jbj's help. I tried to account for all the issues of the first request and indentation and tests.
This error is quite specific, many people think that if memory cannot be allocated, then the program will terminate. However, under conditions of non-criticality for the main program of allocated memory and strong segmentation, a memory leak may form.
In this PR, I consider only two exceptions, the processing of allocated memory with the termination of the main program through the call to exit and assert within the parent function. In the next iteration, I plan to add handling of these situations outside of the function.
Information about the found and accepted fix in the project: NLnetLabs/unbound#341