Skip to content
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

Merged
merged 5 commits into from
May 18, 2018
Merged

General snprintf() hardenings #163

merged 5 commits into from
May 18, 2018

Conversation

kbabioch
Copy link
Contributor

This series makes sure that the return code of snprintf() is always evaluated correctly to make sure it does not run into errors silently.

Copy link
Member

@klali klali left a 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);
Copy link
Member

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);
Copy link
Member

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);
Copy link
Member

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here.

@kbabioch
Copy link
Contributor Author

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.
@klali
Copy link
Member

klali commented May 18, 2018

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.

@klali klali merged commit a68d3be into Yubico:master May 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants