You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on May 13, 2024. It is now read-only.
Undefined behaviours: possible NULL pointer dereference and non-standard declaration of VLA of size 0.
Hello,
I ran electionguard-c under Frama-C today and the analyser has revealed two possible undefined behaviours and/or non-standard practices in examples/api/main.c that I would like to report to you.
Here you can see that localtime() function may return a NULL pointer that gets dereferenced in the next call to snprintf()
Possible patch
Adding a ternary operator for each dereferencing of variable local_time in the call to snprintf checking the validity of that pointer and, if it isn't, passing a default value to snprintf() instead of invalid local_time:
The analyser has revealed that there exist execution traces where variable current_cast_index is equal to 0 when this statement is reached while ISO 9899:2011 6.7.6.2 states:
If the expression is a constant expression, it shall have a value greater than zero.
As I'm not very familiar with the code it would take me to much time to offer a decent possible fix, i felt you should know about it nevertheless.
The text was updated successfully, but these errors were encountered:
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Undefined behaviours: possible NULL pointer dereference and non-standard declaration of VLA of size 0.
Hello,
I ran electionguard-c under Frama-C today and the analyser has revealed two possible undefined behaviours and/or non-standard practices in examples/api/main.c that I would like to report to you.
Null pointer dereferenced
https://github.com/microsoft/electionguard-c/blob/cc2b1be05a38673e523e427e0326eff9678812cb/examples/api/main.c#L102-L109
Here you can see that
localtime()
function may return a NULL pointer that gets dereferenced in the next call tosnprintf()
Possible patch
Adding a ternary operator for each dereferencing of variable
local_time
in the call tosnprintf
checking the validity of that pointer and, if it isn't, passing a default value tosnprintf()
instead of invalidlocal_time
:VLA of size 0 is non-standard
https://github.com/microsoft/electionguard-c/blob/cc2b1be05a38673e523e427e0326eff9678812cb/examples/api/main.c#L255
The analyser has revealed that there exist execution traces where variable
current_cast_index
is equal to 0 when this statement is reached while ISO 9899:2011 6.7.6.2 states:As I'm not very familiar with the code it would take me to much time to offer a decent possible fix, i felt you should know about it nevertheless.
The text was updated successfully, but these errors were encountered: