-
Notifications
You must be signed in to change notification settings - Fork 41
Updated conserver/cutil.c and conserver/group.c to use snprintf( ) vi… #92
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
base: master
Are you sure you want to change the base?
Conversation
…ce sprintf( ) to prevent buffer overflows. Signed-off-by: Anthony Gialluca <agialluc@redhat.com>
conserver/cutil.c
Outdated
| { | ||
| char buf[1024]; | ||
| sprintf(buf, "CONSFILE-%s-%lu-%d.w", progname, | ||
| snprintf(buf, 1024, "CONSFILE-%s-%lu-%d.w", progname, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| snprintf(buf, 1024, "CONSFILE-%s-%lu-%d.w", progname, | |
| snprintf(buf, sizeof(buf), "CONSFILE-%s-%lu-%d.w", progname, |
But if things are crashing here, we know that buf isn't large enough. Given what is written here (and below), that seems unlikely? Probably something else is going on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an excellent recommendation. It makes it much cleaner. With respect to what size buf should be, I am open to what is recommended.
conserver/group.c
Outdated
| return telopts[o]; | ||
| else { | ||
| sprintf(opt, "%d", o); | ||
| snprintf(opt, 128, "%d", o); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| snprintf(opt, 128, "%d", o); | |
| snprintf(opt, sizeof(opt), "%d", o); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again I very much agree with what you are doing, this is an excellent recommendation.
….c with recommended code change. Signed-off-by: Anthony Gialluca <agialluc@redhat.com>
|
I should note, for the record, this may not be the root cause, but is just my suspicion. Regardless, I do think snprintf( ) calls are an improvement. |
robohack
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think these changes will solve any crash -- in cutil.c they are in debug code and anyway the supplied buffer should always be much bigger than any possible expansion of the format string; and in group.c an integer will never be printed as more than 127 decimal digits (unless ints are 420 bits or more).
|
I was a beautiful theory while it lasted. Please feel free to abandon this merge as necessary. |
Updated conserver/cutil.c and conserver/group.c to use snprintf( ) vice sprintf( ) to prevent buffer overflows.
This code change should be carefully checked. I am not normally a coder.