Skip to content

Commit 0e769cc

Browse files
author
git-core
committed
Don't allow garbage instead of real uid in the command line
Replace atoi(3) by strtoul(3), the latter allows to check parse errors
1 parent fc7479f commit 0e769cc

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

su.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,16 @@ int main(int argc, char *argv[])
369369
struct passwd *pw;
370370
pw = getpwnam(argv[optind]);
371371
if (!pw) {
372-
su_to.uid = atoi(argv[optind]);
372+
char *endptr;
373+
374+
/* It seems we shouldn't do this at all */
375+
errno = 0;
376+
su_to.uid = strtoul(argv[optind], &endptr, 10);
377+
if (errno || *endptr) {
378+
LOGE("Unknown id: %s\n", argv[optind]);
379+
fprintf(stderr, "Unknown id: %s\n", argv[optind]);
380+
exit(EXIT_FAILURE);
381+
}
373382
} else {
374383
su_to.uid = pw->pw_uid;
375384
}

0 commit comments

Comments
 (0)