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

newgrp: fix potential string injection #758

Merged
merged 1 commit into from Jul 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/newgrp.c
Expand Up @@ -417,11 +417,18 @@ int main (int argc, char **argv)
* but we do not need to restore the previous process persona and we
* don't need to re-exec anything. -- JWP
*/
Prog = Basename (argv[0]);

/*
* Ensure that "Prog" is always either "newgrp" or "sg" to avoid
* injecting arbitrary strings into our stderr/stdout, as this can
* be an exploit vector.
*/
is_newgrp = (strcmp (Basename (argv[0]), "newgrp") == 0);
Prog = is_newgrp ? "newgrp" : "sg";

log_set_progname(Prog);
log_set_logfd(stderr);
is_newgrp = (strcmp (Prog, "newgrp") == 0);
OPENLOG (is_newgrp ? "newgrp" : "sg");
OPENLOG (Prog);
argc--;
argv++;

Expand Down