-
Notifications
You must be signed in to change notification settings - Fork 373
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
warnings, that asprintf() return code is not checked #471
Comments
I have done now a first check, how the asprintf() allocated memory structures are handled. Looks like, there is something to do. I looked at the first occurence of asprintf(), where asprintf() is used in function myconfig_setting_lookup_stringcpy(). This is only used just once a little bit later in the same c-file as part of a table lookup_fns, where lookup functions are stored. This table with the stored functions is used again in the same file, where we have to differentiate two cases:
The above referenced function is used again in the same file, where as a result of a failing lookup another asprintf() is used, to create an _errmsg__. Now I have two traces. Following the configuration path or having a look at the errmsg. I decided to the latter for my next step:
read_block_setval() is allocating errmsg the first time, two lines later another asprintf() is allocating it the next time. So I see, that sslh has two problems:
I would be glad, if anybody could prove me wrong. |
the good news is:
In log.c the implementation is perfect:
Once sslh-conf.c is cleaned, the solution can be taken over to echosrv-conf.c, as this seems to be just almost a clone and is only used in testing. |
Actually, I think it is in fact only important in log.c, which is used during normal run time.
So altogether not a big deal for That being said, this code is generated by (conf2struct)[https://github.com/yrutschle/conf2struct], which I guess can have use cases where reading a configuration file that fails is not terminal, so it should be handled there. I use |
I reported in #468 warnings, I see with newer compilers.
Its mostly about the use of asprintf(). asprintf() has an implicit malloc() function and needs to be checked like malloc(), to make sure, that no invalid pointers are dangling around.
I have checked some of the locations, and it looks like, that some changes are very easy, others need rewriting of
An easy example looks like:
which could rewritten to:
Other locations are much more difficult:
Here is an error value of "0" returned, and exactly in this case the pointer char**errmsg will be used to report the error. A situation, which should be avoided, if the implicit malloc() of asprintf() failed to reserve the needed memory.
Locations, whith the unchecked asprintf() calls:
What I have not checked yet, if all of the allocated memory from asprintf gets properly deallocated. When I cross-check the source, all malloc() i have seen so far, are checked.
The text was updated successfully, but these errors were encountered: