]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/nss.c: Move '\n' check earlier master
authorAlejandro Colomar <alx@kernel.org>
Tue, 3 Mar 2026 11:29:56 +0000 (12:29 +0100)
committerSerge Hallyn <serge@hallyn.com>
Thu, 11 Jun 2026 12:23:18 +0000 (07:23 -0500)
If a line doesn't have a '\n', this is a problem, and the line should be
rejected, immediately.

Also, remove the '\n' during the check (with stpsep()), because we don't
want it there when handling the string.

Link: <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/V1_chap03.html#tag_03_387>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/nss.c

index 54d22dbcbd99eab2dcef5e191ce30a9e9e8cbced..528eee87cafab7f7df8e42366ee49fc15ec78f24 100644 (file)
--- a/lib/nss.c
+++ b/lib/nss.c
@@ -79,14 +79,18 @@ nss_init(const char *nsswitch_path) {
        }
        p = NULL;
        while (getline(&line, &len, nssfp) != -1) {
+               if (stpsep(line, "\n") == NULL) {
+                       fprintf(log_get_logfd(), "%s: Non-text file.\n", nsswitch_path);
+                       goto null_subid;
+               }
                if (strprefix(line, "#"))
                        continue;
-               if (strlen(line) < 8)
+               if (strlen(line) < 7)
                        continue;
                if (!strcaseprefix(line, "subid:"))
                        continue;
                p = &line[6];
-               p = stpspn(p, " \t\n");
+               p = stpspn(p, " \t");
                if (!streq(p, ""))
                        break;
                p = NULL;
@@ -94,10 +98,6 @@ nss_init(const char *nsswitch_path) {
        if (p == NULL) {
                goto null_subid;
        }
-       if (stpsep(p, "\n") == NULL) {
-               fprintf(log_get_logfd(), "%s: Non-text file.\n", nsswitch_path);
-               goto null_subid;
-       }
        stpsep(p, " \t");
        if (streq(p, "")) {
                fprintf(log_get_logfd(), "No usable subid NSS module found, using files\n");