From: Karel Zak Date: Tue, 7 Jun 2022 07:46:54 +0000 (+0200) Subject: lslogins: fix free(): invalid pointer X-Git-Tag: v2.39-rc1~624 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=890d4d3f236e2d28db35ea9bc9dc3e5e35db975c;p=thirdparty%2Futil-linux.git lslogins: fix free(): invalid pointer Signed-off-by: Karel Zak --- diff --git a/login-utils/lslogins.c b/login-utils/lslogins.c index 3646883e0e..3cb30b74e2 100644 --- a/login-utils/lslogins.c +++ b/login-utils/lslogins.c @@ -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);