libsemanage/backport-libsemanage-avoid-leak-on-realloc-failure.patch
hugel 670213ce64 backport patches from upstream
(cherry picked from commit a6c5156e71001ac8cf1b559ce274e5306006cede)
2025-03-17 17:19:28 +08:00

45 lines
1.3 KiB
Diff

From 73f958b01aa15c55cd69f188b8a5ed44601ac406 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= <cgzones@googlemail.com>
Date: Mon, 11 Nov 2024 15:16:38 +0100
Subject: [PATCH] libsemanage: avoid leak on realloc failure
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
Acked-by: James Carter <jwcart2@gmail.com>
Conflict:NA
Reference:https://github.com/SELinuxProject/selinux/commit/73f958b01aa15c55cd69f188b8a5ed44601ac406
---
src/direct_api.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/src/direct_api.c b/src/direct_api.c
index ed4343dc..288e491a 100644
--- a/src/direct_api.c
+++ b/src/direct_api.c
@@ -599,12 +599,16 @@ static int read_from_pipe_to_data(semanage_handle_t *sh, size_t initial_len, int
while ((read_len = read(fd, data_read + data_read_len, max_len - data_read_len)) > 0) {
data_read_len += read_len;
if (data_read_len == max_len) {
+ char *tmp;
+
max_len *= 2;
- data_read = realloc(data_read, max_len);
- if (data_read == NULL) {
+ tmp = realloc(data_read, max_len);
+ if (tmp == NULL) {
ERR(sh, "Failed to realloc, out of memory.\n");
+ free(data_read);
return -1;
}
+ data_read = tmp;
}
}
--
2.33.0