]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
usermod: fix off-by-one issues
authorChristian Göttsche <cgzones@googlemail.com>
Thu, 2 Mar 2023 15:18:45 +0000 (16:18 +0100)
committerSerge Hallyn <serge@hallyn.com>
Thu, 8 Jun 2023 14:05:39 +0000 (09:05 -0500)
Allocate enough memory for the strings, two slashes and the NUL
terminator.

Reported-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
src/usermod.c

index 77d4ef49193e2c52977b7e76c15610390925f4f5..db5d37a4265ea8effe570fbf5f66c8424c8acff0 100644 (file)
@@ -2048,7 +2048,7 @@ static void move_mailbox (void)
        if (NULL == maildir) {
                return;
        }
-       len = strlen (prefix) + strlen (maildir) + strlen (user_name) + 2;
+       len = strlen (prefix) + strlen (maildir) + strlen (user_name) + 3;
        mailfile = ALLOCARRAY (len, char);
 
        /*
@@ -2103,7 +2103,7 @@ static void move_mailbox (void)
        (void) close (fd);
 
        if (lflg) {
-               len = strlen (prefix) + strlen (maildir) + strlen (user_newname) + 2;
+               len = strlen (prefix) + strlen (maildir) + strlen (user_newname) + 3;
                newmailfile = ALLOCARRAY(len, char);
                if (prefix[0]) {
                        (void) snprintf (newmailfile, len, "%s/%s/%s",