]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
chsh: replace getpw unsafe functions with xgetpw
authorQuentin Rameau <quinq@fifth.space>
Sat, 21 Sep 2019 18:50:21 +0000 (20:50 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 26 Sep 2019 13:55:41 +0000 (15:55 +0200)
login-utils/chsh.c

index 9b2761157342aaffaaf67a61d4a3eb69d9a7bd1b..a9ebec86ff66b8b67cfbb3a871b714f63582c9da 100644 (file)
@@ -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);