-
Notifications
You must be signed in to change notification settings - Fork 114
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
General snprintf() hardenings #163
Conversation
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.
Looks good, a couple of variable declarations that need to move up to start of block, the project compiles with C90..
pam_yubico.c
Outdated
@@ -308,7 +308,11 @@ authorize_user_token_ldap (struct cfg *cfg, | |||
DBG ("Failed allocating %zu bytes", i); | |||
goto done; | |||
} | |||
sprintf (find, "%s=%s,%s", cfg->user_attr, user, cfg->ldapdn); | |||
int j = snprintf (find, i, "%s=%s,%s", cfg->user_attr, user, cfg->ldapdn); |
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.
Please move the variable declaration up to start of the block.
util.c
Outdated
@@ -68,7 +68,10 @@ get_user_cfgfile_path(const char *common_path, const char *filename, const struc | |||
if ((userfile = malloc(len)) == NULL) { | |||
return 0; | |||
} | |||
snprintf(userfile, len, "%s/%s", common_path, filename); | |||
int i = snprintf(userfile, len, "%s/%s", common_path, filename); |
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.
Same thing here, int i needs to move up.
util.c
Outdated
@@ -79,7 +82,10 @@ get_user_cfgfile_path(const char *common_path, const char *filename, const struc | |||
if ((userfile = malloc(len)) == NULL) { | |||
return 0; | |||
} | |||
snprintf(userfile, len, "%s/.yubico/%s", user->pw_dir, filename); | |||
int i = snprintf(userfile, len, "%s/.yubico/%s", user->pw_dir, filename); |
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.
Here as well, please move the declaration up.
util.c
Outdated
@@ -332,7 +338,14 @@ check_user_challenge_file(const char *chalresp_path, const struct passwd *user, | |||
ret = AUTH_ERROR; | |||
goto out; | |||
} | |||
snprintf(userfile_pattern, len, "%s-*", userfile); | |||
|
|||
int i = snprintf(userfile_pattern, len, "%s-*", userfile); |
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.
And here.
Here you go. Shouldn't this be something that would be detected by Travis? |
This moves variable declrations to the beginning of a block to be C90-compliant.
Yes, this should ideally be detected. I compile it with --enable-gcc-warnings to configure, unfortunately that generates noise/things we/I haven't cared about earlier. I try to make sure that changes don't introduce new warnings in that. Looks good, merging. |
This series makes sure that the return code of snprintf() is always evaluated correctly to make sure it does not run into errors silently.