Skip to content

Commit aaa9e71

Browse files
authored
Update setpwnam.c
1 parent c6059d7 commit aaa9e71

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

login-utils/setpwnam.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,12 @@ int setpwnam(struct passwd *pwd, const char *prefix)
126126
}
127127

128128
/* Is this the username we were sent to change? */
129-
if (!found && linebuf[namelen] == ':' &&
130-
!strncmp(linebuf, pwd->pw_name, namelen)) {
131-
/* Yes! So go forth in the name of the Lord and
132-
* change it! */
129+
if (!found &&
130+
strncmp(linebuf, pwd->pw_name, namelen) == 0 &&
131+
strlen(linebuf) > namelen &&
132+
linebuf[namelen] == ':') {
133+
/* Yes! But this time let’s not walk past the end of the buffer
134+
* in the name of the Lord, SUID, or anything else. */
133135
if (putpwent(pwd, fp) < 0)
134136
goto fail;
135137
found = 1;

0 commit comments

Comments
 (0)