← Commit list

0cdd6f579

Denys Vlasenko
Denys Vlasenko
2022-04-27
SUCCESS Duration: 155s

Subject

libbb: fix fallout from nth_string() robustification, closes 14726

Binary

No binary (build failed)

Architecture & Compiler Flags

Architecture: x86_64-linux-gnu Compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0

—

Build Log

(log yok)

Commit Diff GitHub →

libpwdgrp/pwd_grp.c+13 -1
@@ -191,6 +191,9 @@ static char *parse_common(FILE *fp, struct passdb *db,
char *buf;
while ((buf = xmalloc_fgetline(fp)) != NULL) {
+ int n;
+ char *field;
+
/* Skip empty lines, comment lines */
if (buf[0] == '\0' || buf[0] == '#')
goto free_and_next;
@@ -204,7 +207,16 @@ static char *parse_common(FILE *fp, struct passdb *db,
/* no key specified: sequential read, return a record */
break;
}
- if (strcmp(key, nth_string(buf, field_pos)) == 0) {
+ /* Can't use nth_string() here, it does not allow empty strings
+ * ("\0\0" terminates the list), and a valid passwd entry
+ * "user::UID:GID..." would be mishandled */
+ n = field_pos;
+ field = buf;
+ while (n) {
+ n--;
+ field += strlen(field) + 1;
+ }
+ if (strcmp(key, field) == 0) {
/* record found */
break;
}