https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=808a95d24d6aff7191b4ba4710213f283c5e6379
commit 808a95d24d6aff7191b4ba4710213f283c5e6379 Author: Corinna Vinschen <[email protected]> AuthorDate: Sat Feb 24 10:46:54 2024 +0100 Commit: Corinna Vinschen <[email protected]> CommitDate: Sat Feb 24 13:08:33 2024 +0100 Cygwin: newgrp: fix invalid usage of argv Fix an error message accessing argv[1] even after it has been potentially moved. Print group name from group DB instead. Fixes: 8bd56ec873453 ("Cygwin: newgrp: first full version") Signed-off-by: Corinna Vinschen <[email protected]> Diff: --- winsup/utils/newgrp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/winsup/utils/newgrp.c b/winsup/utils/newgrp.c index 88586352e108..e312a3c51d38 100644 --- a/winsup/utils/newgrp.c +++ b/winsup/utils/newgrp.c @@ -160,6 +160,7 @@ main (int argc, const char **argv) if (argv[1] == NULL) { gid = pw->pw_gid; + gr = getgrgid (gid); } else { @@ -179,7 +180,7 @@ main (int argc, const char **argv) if (setgid (gid) != 0) { fprintf (stderr, "%s: can't switch primary group to '%s'\n", - program_invocation_short_name, argv[1]); + program_invocation_short_name, gr->gr_name); return 2; }
