Void Linux discussion
 help / color / mirror / Atom feed
From: Quentin Rameau <quinq@fifth.space>
To: Void Linux <voidlinux@googlegroups.com>
Cc: Quentin Rameau <quinq@fifth.space>
Subject: [PATCH 2/2] chsh: replace getpw unsafe functions with xgetpw
Date: Sun, 22 Sep 2019 15:12:37 +0200	[thread overview]
Message-ID: <20190922131237.93849-3-quinq@fifth.space> (raw)
In-Reply-To: <20190922131237.93849-1-quinq@fifth.space>

---
 login-utils/chsh.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/login-utils/chsh.c b/login-utils/chsh.c
index 9b2761157..a9ebec86f 100644
--- a/login-utils/chsh.c
+++ b/login-utils/chsh.c
@@ -38,6 +38,7 @@
 #include "islocal.h"
 #include "nls.h"
 #include "pathnames.h"
+#include "pwdutils.h"
 #include "setpwnam.h"
 #include "strutils.h"
 #include "xalloc.h"
@@ -253,7 +254,7 @@ static void check_shell(const char *shell)
 
 int main(int argc, char **argv)
 {
-	char *oldshell;
+	char *oldshell, *pwbuf;
 	int nullshell = 0;
 	const uid_t uid = getuid();
 	struct sinfo info = { NULL };
@@ -267,12 +268,12 @@ int main(int argc, char **argv)
 
 	parse_argv(argc, argv, &info);
 	if (!info.username) {
-		pw = getpwuid(uid);
+		pw = xgetpwuid(uid, &pwbuf);
 		if (!pw)
 			errx(EXIT_FAILURE, _("you (user %d) don't exist."),
 			     uid);
 	} else {
-		pw = getpwnam(info.username);
+		pw = xgetpwnam(info.username, &pwbuf);
 		if (!pw)
 			errx(EXIT_FAILURE, _("user \"%s\" does not exist."),
 			     info.username);
-- 
2.21.0

-- 
You received this message because you are subscribed to the Google Groups "voidlinux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to voidlinux+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/voidlinux/20190922131237.93849-3-quinq%40fifth.space.

      parent reply	other threads:[~2019-09-22 13:12 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-22 13:12 Fix for chsh (util-linux) Quentin Rameau
2019-09-22 13:12 ` [PATCH 1/2] lib/pwdutils: add xgetpwuid Quentin Rameau
2019-09-22 13:12 ` Quentin Rameau [this message]

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=20190922131237.93849-3-quinq@fifth.space \
    --to=quinq@fifth.space \
    --cc=voidlinux@googlegroups.com \
    /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 NNTP newsgroup(s).