util-linux/backport-lslogins-fix-free-invalid-pointer.patch
zhangyao e4b266fdf2 sync community patches
(cherry picked from commit 6dd51158f697e8922904bf11109bd894487a9419)
2023-06-05 15:48:48 +08:00

34 lines
1.1 KiB
Diff

From 890d4d3f236e2d28db35ea9bc9dc3e5e35db975c Mon Sep 17 00:00:00 2001
From: Karel Zak <kzak@redhat.com>
Date: Tue, 7 Jun 2022 09:46:54 +0200
Subject: [PATCH] lslogins: fix free(): invalid pointer
Signed-off-by: Karel Zak <kzak@redhat.com>
---
login-utils/lslogins.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
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);