Blame SOURCES/0007-libsemanage-Fix-USE_AFTER_FREE-CWE-672-in-semanage_d.patch

83eaee
From 30da7a4907893bd43fe9da40728a3bcabdf3d7a4 Mon Sep 17 00:00:00 2001
83eaee
From: Petr Lautrbach <plautrba@redhat.com>
83eaee
Date: Wed, 28 Jul 2021 11:21:35 +0200
83eaee
Subject: [PATCH] libsemanage: Fix USE_AFTER_FREE (CWE-672) in
83eaee
 semanage_direct_write_langext()
83eaee
83eaee
>From fclose(3):
83eaee
Upon successful completion, 0 is returned.  Otherwise, EOF is returned
83eaee
and errno is set to indicate the error. In either case, any further
83eaee
access (including another call to fclose()) to the stream results in
83eaee
undefined behavior.
83eaee
83eaee
Fixes:
83eaee
    Error: USE_AFTER_FREE (CWE-672): [#def1]
83eaee
    libsemanage-3.2/src/direct_api.c:1023: freed_arg: "fclose" frees "fp".
83eaee
    libsemanage-3.2/src/direct_api.c:1034: use_closed_file: Calling "fclose" uses file handle "fp" after closing it.
83eaee
    # 1032|
83eaee
    # 1033|   cleanup:
83eaee
    # 1034|-> 	if (fp != NULL) fclose(fp);
83eaee
    # 1035|
83eaee
    # 1036|   	return ret;
83eaee
83eaee
Signed-off-by: Petr Lautrbach <plautrba@redhat.com>
83eaee
---
83eaee
 libsemanage/src/direct_api.c | 1 +
83eaee
 1 file changed, 1 insertion(+)
83eaee
83eaee
diff --git a/libsemanage/src/direct_api.c b/libsemanage/src/direct_api.c
83eaee
index c32939c0..7638653a 100644
83eaee
--- a/libsemanage/src/direct_api.c
83eaee
+++ b/libsemanage/src/direct_api.c
83eaee
@@ -1022,6 +1022,7 @@ static int semanage_direct_write_langext(semanage_handle_t *sh,
83eaee
 
83eaee
 	if (fclose(fp) != 0) {
83eaee
 		ERR(sh, "Unable to close %s module ext file.", modinfo->name);
83eaee
+		fp = NULL;
83eaee
 		ret = -1;
83eaee
 		goto cleanup;
83eaee
 	}
83eaee
-- 
83eaee
2.30.2
83eaee