]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/nss.c: Fix use of uninitialized p
authorAlejandro Colomar <alx@kernel.org>
Wed, 31 May 2023 10:19:33 +0000 (12:19 +0200)
committerSerge Hallyn <serge@hallyn.com>
Wed, 31 May 2023 14:29:49 +0000 (09:29 -0500)
getline(3) might have never succeeded, in which case p is uninitialized
when used in strtok_r(3).

Link: <https://github.com/shadow-maint/shadow/pull/737#discussion_r1206007358>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/nss.c

index 1aa27f3e5cf917e42bd3966ca41ce8fa95e7d055..e6776fb1aa460a8fbf2c57da82b3ec11446ed3e4 100644 (file)
--- a/lib/nss.c
+++ b/lib/nss.c
@@ -69,7 +69,8 @@ void nss_init(const char *nsswitch_path) {
                atomic_store(&nss_init_completed, true);
                return;
        }
-       while ((getline(&line, &len, nssfp)) != -1) {
+       p = NULL;
+       while (getline(&line, &len, nssfp) != -1) {
                if (line[0] == '#')
                        continue;
                if (strlen(line) < 8)
@@ -82,6 +83,9 @@ void nss_init(const char *nsswitch_path) {
                if (*p != '\0')
                        break;
        }
+       if (p == NULL) {
+               goto null_subid;
+       }
        token = strtok_r(p, " \n\t", &saveptr);
        if (token == NULL) {
                fprintf(shadow_logfd, "No usable subid NSS module found, using files\n");