]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
Update setpwnam.c
authorMohamed Maatallah <hotelsmaatallahrecemail@gmail.com>
Sat, 24 May 2025 02:16:09 +0000 (03:16 +0100)
committerGitHub <noreply@github.com>
Sat, 24 May 2025 02:16:09 +0000 (03:16 +0100)
login-utils/setpwnam.c

index 3e3c1abde509e991ac9e84f73649d7abfcdfe424..95e470b5a3401476c858eb2c827a7db71f56a095 100644 (file)
@@ -126,10 +126,12 @@ int setpwnam(struct passwd *pwd, const char *prefix)
                }
 
                /* Is this the username we were sent to change? */
-               if (!found && linebuf[namelen] == ':' &&
-                   !strncmp(linebuf, pwd->pw_name, namelen)) {
-                       /* Yes! So go forth in the name of the Lord and
-                        * change it!  */
+               if (!found &&
+                   strncmp(linebuf, pwd->pw_name, namelen) == 0 &&
+                   strlen(linebuf) > namelen &&
+                   linebuf[namelen] == ':') {
+                       /* Yes! But this time let’s not walk past the end of the buffer
+                        * in the name of the Lord, SUID, or anything else. */
                        if (putpwent(pwd, fp) < 0)
                                goto fail;
                        found = 1;