]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
src/login.c: Fix off-by-one bugss
authorAlejandro Colomar <alx@kernel.org>
Mon, 5 Feb 2024 12:54:25 +0000 (13:54 +0100)
committerSerge Hallyn <serge@hallyn.com>
Tue, 13 Feb 2024 22:13:05 +0000 (16:13 -0600)
These functions expect a size, not a length.  Don't subtract 1 to the
size.

Link: <https://github.com/shadow-maint/shadow/pull/935>
Link: <https://github.com/shadow-maint/shadow/issues/920#issuecomment-1926002209>
Link: <https://github.com/shadow-maint/shadow/pull/757>
Link: <https://github.com/shadow-maint/shadow/issues/674>
See-also: 0656a90bfd0d ("src/login.c: Fix off-by-one buggs")
See-also: 403a2e3771be ("lib/chkname.c: Take NUL byte into account")
Fixes: 3b7cc053872c ("lib: replace `USER_NAME_MAX_LENGTH` macro")
Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Cc: Tobias Stoeckmann <tobias@stoeckmann.org>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
src/login.c

index c1bc5633dbb1e43c309a713b4b2ff46fb17ca50a..9ae86a7fd6672eb7015c43a6ac8c90ab6f667ec5 100644 (file)
@@ -577,7 +577,7 @@ int main (int argc, char **argv)
                assert (NULL == username);
                username = XMALLOC(max_size, char);
                username[max_size - 1] = '\0';
-               if (do_rlogin(hostname, username, max_size - 1, term, sizeof(term)))
+               if (do_rlogin(hostname, username, max_size, term, sizeof(term)))
                {
                        preauth_flag = true;
                } else {
@@ -890,7 +890,7 @@ int main (int argc, char **argv)
                        preauth_flag = false;
                        username = XMALLOC(max_size, char);
                        username[max_size - 1] = '\0';
-                       login_prompt(username, max_size - 1);
+                       login_prompt(username, max_size);
 
                        if ('\0' == username[0]) {
                                /* Prompt for a new login */