diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2022-04-27 15:29:57 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2022-04-27 15:33:55 +0200 |
commit | 0cdd6f579256d7dcbf48548ee470b8bb54a7de64 (patch) | |
tree | ba09a44658be4a6bd7220b5d3afec5720be5692e | |
parent | 7fbfb2050f24a457a909ea6bcec85c49a21db83a (diff) | |
download | busybox-w32-0cdd6f579256d7dcbf48548ee470b8bb54a7de64.tar.gz busybox-w32-0cdd6f579256d7dcbf48548ee470b8bb54a7de64.tar.bz2 busybox-w32-0cdd6f579256d7dcbf48548ee470b8bb54a7de64.zip |
libbb: fix fallout from nth_string() robustification, closes 14726
function old new delta
parse_common 187 228 +41
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | libpwdgrp/pwd_grp.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/libpwdgrp/pwd_grp.c b/libpwdgrp/pwd_grp.c index b44ada432..10debbcdb 100644 --- a/libpwdgrp/pwd_grp.c +++ b/libpwdgrp/pwd_grp.c | |||
@@ -191,6 +191,9 @@ static char *parse_common(FILE *fp, struct passdb *db, | |||
191 | char *buf; | 191 | char *buf; |
192 | 192 | ||
193 | while ((buf = xmalloc_fgetline(fp)) != NULL) { | 193 | while ((buf = xmalloc_fgetline(fp)) != NULL) { |
194 | int n; | ||
195 | char *field; | ||
196 | |||
194 | /* Skip empty lines, comment lines */ | 197 | /* Skip empty lines, comment lines */ |
195 | if (buf[0] == '\0' || buf[0] == '#') | 198 | if (buf[0] == '\0' || buf[0] == '#') |
196 | goto free_and_next; | 199 | goto free_and_next; |
@@ -204,7 +207,16 @@ static char *parse_common(FILE *fp, struct passdb *db, | |||
204 | /* no key specified: sequential read, return a record */ | 207 | /* no key specified: sequential read, return a record */ |
205 | break; | 208 | break; |
206 | } | 209 | } |
207 | if (strcmp(key, nth_string(buf, field_pos)) == 0) { | 210 | /* Can't use nth_string() here, it does not allow empty strings |
211 | * ("\0\0" terminates the list), and a valid passwd entry | ||
212 | * "user::UID:GID..." would be mishandled */ | ||
213 | n = field_pos; | ||
214 | field = buf; | ||
215 | while (n) { | ||
216 | n--; | ||
217 | field += strlen(field) + 1; | ||
218 | } | ||
219 | if (strcmp(key, field) == 0) { | ||
208 | /* record found */ | 220 | /* record found */ |
209 | break; | 221 | break; |
210 | } | 222 | } |