diff -rNU3 openssh-9.0p1.old/loginrec.c openssh-9.0p1/loginrec.c
--- openssh-9.0p1.old/loginrec.c	2022-04-06 02:47:48.000000000 +0200
+++ openssh-9.0p1/loginrec.c	2022-07-11 14:59:44.848827188 +0200
@@ -763,10 +763,6 @@
 	set_utmpx_time(li, utx);
 	utx->ut_pid = li->pid;
 
-	/* strncpy(): Don't necessarily want null termination */
-	strncpy(utx->ut_user, li->username,
-	    MIN_SIZEOF(utx->ut_user, li->username));
-
 	if (li->type == LTYPE_LOGOUT)
 		return;
 
@@ -775,6 +771,10 @@
 	 * for logouts.
 	 */
 
+	/* strncpy(): Don't necessarily want null termination */
+	strncpy(utx->ut_user, li->username,
+	    MIN_SIZEOF(utx->ut_user, li->username));
+
 # ifdef HAVE_HOST_IN_UTMPX
 	strncpy(utx->ut_host, li->hostname,
 	    MIN_SIZEOF(utx->ut_host, li->hostname));