usermod: fix off-by-one issues

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>
This commit is contained in:
Christian Göttsche 2023-03-02 16:18:45 +01:00 committed by Serge Hallyn
parent 170d24a251
commit 7a2b302e68

View 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",