We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c6059d7 commit aaa9e71Copy full SHA for aaa9e71
login-utils/setpwnam.c
@@ -126,10 +126,12 @@ int setpwnam(struct passwd *pwd, const char *prefix)
126
}
127
128
/* 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! */
+ if (!found &&
+ strncmp(linebuf, pwd->pw_name, namelen) == 0 &&
+ strlen(linebuf) > namelen &&
+ 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. */
135
if (putpwent(pwd, fp) < 0)
136
goto fail;
137
found = 1;
0 commit comments