]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lslogins: fix free(): invalid pointer
authorKarel Zak <kzak@redhat.com>
Tue, 7 Jun 2022 07:46:54 +0000 (09:46 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 7 Jun 2022 07:46:54 +0000 (09:46 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
login-utils/lslogins.c

index 3646883e0ef6807ed4153e21116ee83e878b5fce..3cb30b74e224b388046cfd40939f625237a887d3 100644 (file)
@@ -490,7 +490,7 @@ static int parse_utmpx(const char *path, size_t *nrecords, struct utmpx **record
 
        /* optimize allocation according to file size, the realloc() below is
         * just fallback only */
-       if (stat(path, &st) == 0 && (size_t) st.st_size > sizeof(struct utmpx)) {
+       if (stat(path, &st) == 0 && (size_t) st.st_size >= sizeof(struct utmpx)) {
                imax = st.st_size / sizeof(struct utmpx);
                ary = xmalloc(imax * sizeof(struct utmpx));
        }
@@ -1013,6 +1013,9 @@ static void free_ctl(struct lslogins_control *ctl)
 {
        size_t n = 0;
 
+       if (!ctl)
+               return;
+
        free(ctl->wtmp);
        free(ctl->btmp);