diff --git a/lib/nss.c b/lib/nss.c index 5957390741..fb739ff073 100644 --- 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,7 +98,8 @@ nss_init(const char *nsswitch_path) { if (p == NULL) { goto null_subid; } - if (stpsep(p, " \t\n") == NULL) { + stpsep(p, " \t"); + if (streq(p, "")) { fprintf(log_get_logfd(), "No usable subid NSS module found, using files\n"); // subid_nss has to be null here, but to ease reviews: goto null_subid;