public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
From: Corinna Vinschen <corinna@sourceware.org>
To: cygwin-cvs@sourceware.org
Subject: [newlib-cygwin/main] Cygwin: newgrp: fix invalid usage of argv
Date: Sat, 24 Feb 2024 12:14:03 +0000 (GMT)	[thread overview]
Message-ID: <20240224121403.8BB1B385828C@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=808a95d24d6aff7191b4ba4710213f283c5e6379

commit 808a95d24d6aff7191b4ba4710213f283c5e6379
Author:     Corinna Vinschen <corinna@vinschen.de>
AuthorDate: Sat Feb 24 10:46:54 2024 +0100
Commit:     Corinna Vinschen <corinna@vinschen.de>
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 <corinna@vinschen.de>

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;
     }

                 reply	other threads:[~2024-02-24 12:14 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240224121403.8BB1B385828C@sourceware.org \
    --to=corinna@sourceware.org \
    --cc=cygwin-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).