dcavalca / rpms / util-linux

Forked from rpms/util-linux 2 years ago
Clone
d8d8bc
From c269e116ea4d9e96a5f5801aecf1f624199fa6ec Mon Sep 17 00:00:00 2001
d8d8bc
From: Karel Zak <kzak@redhat.com>
d8d8bc
Date: Tue, 7 Jun 2022 09:46:54 +0200
d8d8bc
Subject: lslogins: fix free(): invalid pointer
d8d8bc
d8d8bc
Upstream: http://github.com/util-linux/util-linux/commit/890d4d3f236e2d28db35ea9bc9dc3e5e35db975c
d8d8bc
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=2094216
d8d8bc
Signed-off-by: Karel Zak <kzak@redhat.com>
d8d8bc
---
d8d8bc
 login-utils/lslogins.c | 5 ++++-
d8d8bc
 1 file changed, 4 insertions(+), 1 deletion(-)
d8d8bc
d8d8bc
diff --git a/login-utils/lslogins.c b/login-utils/lslogins.c
d8d8bc
index 1332a9925..ff4386d1b 100644
d8d8bc
--- a/login-utils/lslogins.c
d8d8bc
+++ b/login-utils/lslogins.c
d8d8bc
@@ -488,7 +488,7 @@ static int parse_utmpx(const char *path, size_t *nrecords, struct utmpx **record
d8d8bc
 
d8d8bc
 	/* optimize allocation according to file size, the realloc() below is
d8d8bc
 	 * just fallback only */
d8d8bc
-	if (stat(path, &st) == 0 && (size_t) st.st_size > sizeof(struct utmpx)) {
d8d8bc
+	if (stat(path, &st) == 0 && (size_t) st.st_size >= sizeof(struct utmpx)) {
d8d8bc
 		imax = st.st_size / sizeof(struct utmpx);
d8d8bc
 		ary = xmalloc(imax * sizeof(struct utmpx));
d8d8bc
 	}
d8d8bc
@@ -1007,6 +1007,9 @@ static void free_ctl(struct lslogins_control *ctl)
d8d8bc
 {
d8d8bc
 	size_t n = 0;
d8d8bc
 
d8d8bc
+	if (!ctl)
d8d8bc
+		return;
d8d8bc
+
d8d8bc
 	free(ctl->wtmp);
d8d8bc
 	free(ctl->btmp);
d8d8bc
 
d8d8bc
-- 
d8d8bc
2.36.1
d8d8bc