-
Notifications
You must be signed in to change notification settings - Fork 104
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
Various small fixes #90
Conversation
- check for malloc returning NULL - do not leak memory on error coniditions
- check for malloc returning NULL - do not leak memory on error coniditions
- check for malloc returning NULL - do not leak memory on error coniditions
- remove check for 31 - use 64bit type for the internal calculation
- check for malloc returning NULL - do not leak memory on error coniditions
Thanks for the various fixes. In general, I try to keep the code short and I prefer to have memory leaks if the program is going to end than making a very long and verbose code. There are some of your fixes that I might include in the future, though. I also prefer to make these changes myself. If you are willing to suggest changes, I prefer issues to PR for this reason. Closing. |
I agree that memory leaks in a program that runs once may be OK. Not checking for malloc returning NULL is not a good idea, maybe a wrapper that aborts will help you to keep to code short and still make it safe. What was important in this PR is commit f59f224... |
I will have a look at the malloc thing, thanks for your suggestion. It is such a controversial topic (I found this interesting discussion about it https://stackoverflow.com/questions/763159/should-i-bother-detecting-oom-out-of-memory-errors-in-my-c-code). Regarding the commit f59f224, I don't see any bug in there. Indeed, the program is usually allocating more memory than it will need, and it's also true that if However, in the end, I agree that this part is not well designed. I will change that and review similar parts of the code to find similar issues. Thank you very much for your time reviewing this! |
About commit f59f224:
then
With this This is not reported unless the program is built with _FORTIFY_SOURCE=2; only then the program prints:
BTW. _FORTIFY_SOURCE=2 is part of the default build options on most modern distributions - I would not consider that one dangerous in any way... |
I understand your point, but the situation in which tmp1 and tmp2 becomes more than 12 is only possible if one (or both) has a length bigger than 6 characters. Honestly I am unable to find a value that can cause that Can you post the CPU model which caused the issue? Thanks. |
Sorry, I couldn't find the exact server where it aborted but the example above is showing that 13.75MB is 7 chars... Maybe it was AMD? Anyways - I see no point guessing the size - regardless if the calculation is right or wrong, the value used in As I look into |
Yeah, I agree, that is why I said that I am going to redesign this part. These days I have been doing stuff in different parts of the code and I have detected many cases like this (bad designed code). Some parts of the code are old, or they were just not very well done from the beginning. I will go through the code to fix these small issues. And I will also consider adding Thanks for your tips! |
The OOB can be seen as the following output:
./cpufetch
*** buffer overflow detected ***: terminated
Aborted