Blame SOURCES/0004-mcstrans-fix-RESOURCE_LEAK-CWE-772.patch

a5f30d
From 52872e0193f650b1fd4ab9125453e7ebdac152bd Mon Sep 17 00:00:00 2001
a5f30d
From: Petr Lautrbach <plautrba@redhat.com>
a5f30d
Date: Thu, 5 Aug 2021 16:26:44 +0200
a5f30d
Subject: [PATCH] mcstrans: fix RESOURCE_LEAK (CWE-772)
a5f30d
a5f30d
Fixes:
a5f30d
    Error: RESOURCE_LEAK (CWE-772): [#def1]
a5f30d
    mcstrans-3.2/src/mcstrans.c:1527: alloc_fn: Storage is returned from allocation function "compute_trans_from_raw".
a5f30d
    mcstrans-3.2/src/mcstrans.c:1527: var_assign: Assigning: "trans" = storage returned from "compute_trans_from_raw(range, domain)".
a5f30d
    mcstrans-3.2/src/mcstrans.c:1529: noescape: Resource "trans" is not freed or pointed-to in "add_cache".
a5f30d
    mcstrans-3.2/src/mcstrans.c:1515: overwrite_var: Overwriting "trans" in "trans = find_in_hashtable(range, domain, domain->raw_to_trans)" leaks the storage that "trans" points to.
a5f30d
    # 1513|   	domain_t *domain = domains;
a5f30d
    # 1514|   	for (;domain; domain = domain->next) {
a5f30d
    # 1515|-> 		trans = find_in_hashtable(range, domain, domain->raw_to_trans);
a5f30d
    # 1516|   		if (trans) break;
a5f30d
    # 1517|
a5f30d
a5f30d
    Error: RESOURCE_LEAK (CWE-772): [#def2]
a5f30d
    mcstrans-3.2/src/mcstrans.c:1654: alloc_fn: Storage is returned from allocation function "compute_raw_from_trans".
a5f30d
    mcstrans-3.2/src/mcstrans.c:1654: var_assign: Assigning: "raw" = storage returned from "compute_raw_from_trans(range, domain)".
a5f30d
    mcstrans-3.2/src/mcstrans.c:1656: noescape: Resource "raw" is not freed or pointed-to in "find_in_hashtable".
a5f30d
    mcstrans-3.2/src/mcstrans.c:1669: noescape: Resource "raw" is not freed or pointed-to in "add_cache".
a5f30d
    mcstrans-3.2/src/mcstrans.c:1642: overwrite_var: Overwriting "raw" in "raw = find_in_hashtable(range, domain, domain->trans_to_raw)" leaks the storage that "raw" points to.
a5f30d
    # 1640|   	domain_t *domain = domains;
a5f30d
    # 1641|   	for (;domain; domain = domain->next) {
a5f30d
    # 1642|-> 		raw = find_in_hashtable(range, domain, domain->trans_to_raw);
a5f30d
    # 1643|   		if (raw) break;
a5f30d
    # 1644|
a5f30d
a5f30d
Signed-off-by: Petr Lautrbach <plautrba@redhat.com>
a5f30d
---
a5f30d
 mcstrans/src/mcstrans.c | 8 ++++++++
a5f30d
 1 file changed, 8 insertions(+)
a5f30d
a5f30d
diff --git a/mcstrans/src/mcstrans.c b/mcstrans/src/mcstrans.c
a5f30d
index 8678418a1570..4e110e02f73a 100644
a5f30d
--- a/mcstrans/src/mcstrans.c
a5f30d
+++ b/mcstrans/src/mcstrans.c
a5f30d
@@ -1598,6 +1598,10 @@ trans_context(const char *incon, char **rcon) {
a5f30d
 		}
a5f30d
 		if (dashp)
a5f30d
 			*dashp = '-';
a5f30d
+		if (trans) {
a5f30d
+			free(trans);
a5f30d
+			trans = NULL;
a5f30d
+		}
a5f30d
 	}
a5f30d
 
a5f30d
 	if (trans) {
a5f30d
@@ -1769,6 +1773,10 @@ untrans_context(const char *incon, char **rcon) {
a5f30d
 		}
a5f30d
 		if (dashp)
a5f30d
 			*dashp = '-';
a5f30d
+		if (raw) {
a5f30d
+			free(raw);
a5f30d
+			raw = NULL;
a5f30d
+		}
a5f30d
 	}
a5f30d
 
a5f30d
 	if (raw) {
a5f30d
-- 
a5f30d
2.32.0
a5f30d