dcavalca / rpms / util-linux

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