Skip to content

Commit 5cb096f

Browse files
lib/nss.c: Verify that lines are complete
If a line doesn't have a '\n', this is a problem, and the line should be rejected. Also, remove the '\n' during the check (with stpsep()), because we don't want it there when handling the string. That stpsep() call had an error message, which I'm not sure what it really meant. I've removed it, because I don't know what better to do with it. 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>
1 parent 910ec72 commit 5cb096f

1 file changed

Lines changed: 4 additions & 7 deletions

File tree

lib/nss.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,26 +79,23 @@ nss_init(const char *nsswitch_path) {
7979
}
8080
p = NULL;
8181
while (getline(&line, &len, nssfp) != -1) {
82+
if (stpsep(line, "\n") == NULL)
83+
continue;
8284
if (strprefix(line, "#"))
8385
continue;
84-
if (strlen(line) < 8)
86+
if (strlen(line) < 7)
8587
continue;
8688
if (!strcaseprefix(line, "subid:"))
8789
continue;
8890
p = &line[6];
89-
p = stpspn(p, " \t\n");
91+
p = stpspn(p, " \t");
9092
if (!streq(p, ""))
9193
break;
9294
p = NULL;
9395
}
9496
if (p == NULL) {
9597
goto null_subid;
9698
}
97-
if (stpsep(p, "\n") == NULL) {
98-
fprintf(log_get_logfd(), "No usable subid NSS module found, using files\n");
99-
// subid_nss has to be null here, but to ease reviews:
100-
goto null_subid;
101-
}
10299
stpsep(p, " \t");
103100
if (streq(p, "files")) {
104101
goto null_subid;

0 commit comments

Comments
 (0)