]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
utmp: call prepare_utmp() even if utent is NULL
authorIker Pedrosa <ipedrosa@redhat.com>
Fri, 15 Sep 2023 07:55:02 +0000 (09:55 +0200)
committerSerge Hallyn <serge@hallyn.com>
Fri, 15 Sep 2023 17:57:16 +0000 (12:57 -0500)
update_utmp() should also return 0 when success.

Fixes: 1f368e1c1838de9d476a36897d7c53394569de08 ("utmp: update
`update_utmp()")
Resolves: https://github.com/shadow-maint/shadow/issues/805

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
lib/utmp.c

index 9b173327ac7ad90e9c77bd2c3997402eb19a4f7d..e0ae48a0830448e1ec768fe4774aa6c8c49605c5 100644 (file)
@@ -370,17 +370,16 @@ int update_utmp (const char *user,
        struct utmp *utent, *ut;
 
        utent = get_current_utmp ();
-       if (utent == NULL) {
-               return -1;
-       }
-
        ut = prepare_utmp  (user, tty, host, utent);
 
        (void) setutmp  (ut);   /* make entry in the utmp & wtmp files */
-       free (utent);
+
+       if (utent != NULL) {
+               free (utent);
+       }
        free (ut);
 
-       return 1;
+       return 0;
 }
 
 void record_failure(const char *failent_user,