Skip to content

Commit

Permalink
Avoid buffer overflow when /etc/passwd is wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
Moe-hacker committed Nov 22, 2024
1 parent f2259f6 commit 9c6d2c4
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/passwd.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ static char *line_get_username(const char *_Nonnull p)
// /etc/passwd format:
// name:password:uid:gid:comment:home directory:login shell
// So we only need the string before the first colon.
for (int i = 0; p[i] != '\0'; i++) {
for (int i = 0; p[i] != '\0' && i < (LOGIN_NAME_MAX * 2); i++) {
if (p[i] == ':') {
break;
}
Expand Down

0 comments on commit 9c6d2c4

Please sign in to comment.