libsemanage/backport-libsemanage-avoid-double-fclose.patch
zgzxx a249fab278 backport patches from upstream
(cherry picked from commit b35a0b4145912aaf1c58580ed922c68a38996158)
2023-06-13 19:18:25 +08:00

57 lines
1.8 KiB
Diff
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

From e205e3e84a87ab0416d0d990d7534e6ea968332b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= <cgzones@googlemail.com>
Date: Fri, 8 Apr 2022 15:10:54 +0200
Subject: [PATCH] libsemanage: avoid double fclose
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
The cleanup goto block in `semanage_direct_set_enabled()` closes the
file stream pointer fp if not NULL. Set the stream to NULL after a
manual fclose(3), even on failure.
direct_api.c: In function semanage_direct_set_enabled:
direct_api.c:2130:25: error: pointer fp may be used after fclose [-Werror=use-after-free]
2130 | if (fp != NULL) fclose(fp);
| ^~~~~~~~~~
direct_api.c:2092:29: note: call to fclose here
2092 | if (fclose(fp) != 0) {
| ^~~~~~~~~~
Acked-by: James Carter <jwcart2@gmail.com>
Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
Reference: https://github.com/SELinuxProject/selinux/commit/e205e3e84a87ab0416d0d990d7534e6ea968332b
Conflict: Modify the file paths
---
libsemanage/src/direct_api.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/direct_api.c b/src/direct_api.c
index d5716ce5..7206483a 100644
--- a/src/direct_api.c
+++ b/src/direct_api.c
@@ -2089,7 +2089,9 @@ static int semanage_direct_set_enabled(semanage_handle_t *sh,
goto cleanup;
}
- if (fclose(fp) != 0) {
+ ret = fclose(fp);
+ fp = NULL;
+ if (ret != 0) {
ERR(sh,
"Unable to close disabled file for module %s",
modkey->name);
@@ -2097,8 +2099,6 @@ static int semanage_direct_set_enabled(semanage_handle_t *sh,
goto cleanup;
}
- fp = NULL;
-
break;
case 1: /* enable the module */
if (unlink(fn) < 0) {
--
2.27.0