Blame SOURCES/openscap-1.3.4-fix_memory_leaks-PR_1595.patch

8b65ee
From e3d754aad633f2f2ad2735a2eea63f84258fbea7 Mon Sep 17 00:00:00 2001
8b65ee
From: =?UTF-8?q?Jan=20=C4=8Cern=C3=BD?= <jcerny@redhat.com>
8b65ee
Date: Mon, 7 Sep 2020 13:57:17 +0200
8b65ee
Subject: [PATCH 1/8] Plug a memory leak
8b65ee
8b65ee
When the key is already present in the hash table the values
8b65ee
are not inserted to the hash table therefore they are not
8b65ee
freed when the hash table is destroyed.
8b65ee
8b65ee
Addressing:
8b65ee
6 bytes in 1 blocks are definitely lost in loss record 2 of 234
8b65ee
   at 0x483A809: malloc (vg_replace_malloc.c:307)
8b65ee
   by 0x489F5DB: oscap_vsprintf (util.c:146)
8b65ee
   by 0x489F6DD: oscap_sprintf (util.c:160)
8b65ee
   by 0x4921E77: _xccdf_session_export_oval_result_file (xccdf_session.c:1493)
8b65ee
   by 0x492209E: _build_oval_result_sources (xccdf_session.c:1538)
8b65ee
   by 0x492210F: xccdf_session_export_oval (xccdf_session.c:1552)
8b65ee
   by 0x410F77: app_evaluate_xccdf (oscap-xccdf.c:592)
8b65ee
   by 0x40FFF8: oscap_module_call (oscap-tool.c:292)
8b65ee
   by 0x4104C5: oscap_module_process (oscap-tool.c:382)
8b65ee
   by 0x4130A9: main (oscap.c:88)
8b65ee
8b65ee
45 bytes in 1 blocks are definitely lost in loss record 124 of 234
8b65ee
   at 0x483A809: malloc (vg_replace_malloc.c:307)
8b65ee
   by 0x52262DE: strdup (in /usr/lib64/libc-2.31.so)
8b65ee
   by 0x491E383: oscap_strdup (util.h:312)
8b65ee
   by 0x4921E97: _xccdf_session_export_oval_result_file (xccdf_session.c:1495)
8b65ee
   by 0x492209E: _build_oval_result_sources (xccdf_session.c:1538)
8b65ee
   by 0x492210F: xccdf_session_export_oval (xccdf_session.c:1552)
8b65ee
   by 0x410F77: app_evaluate_xccdf (oscap-xccdf.c:592)
8b65ee
   by 0x40FFF8: oscap_module_call (oscap-tool.c:292)
8b65ee
   by 0x4104C5: oscap_module_process (oscap-tool.c:382)
8b65ee
   by 0x4130A9: main (oscap.c:88)
8b65ee
---
8b65ee
 src/XCCDF/xccdf_session.c | 8 ++++++--
8b65ee
 1 file changed, 6 insertions(+), 2 deletions(-)
8b65ee
8b65ee
diff --git a/src/XCCDF/xccdf_session.c b/src/XCCDF/xccdf_session.c
8b65ee
index 25257e5106..cc7ac57c56 100644
8b65ee
--- a/src/XCCDF/xccdf_session.c
8b65ee
+++ b/src/XCCDF/xccdf_session.c
8b65ee
@@ -1493,8 +1493,12 @@ static char *_xccdf_session_export_oval_result_file(struct xccdf_session *sessio
8b65ee
 	char *report_id = oscap_sprintf("oval%d", counter++);
8b65ee
 	const char *original_name = oval_agent_get_filename(oval_session);
8b65ee
 	char *results_file_name = oscap_strdup(name);
8b65ee
-	oscap_htable_add(session->oval.results_mapping, original_name, results_file_name);
8b65ee
-	oscap_htable_add(session->oval.arf_report_mapping, original_name, report_id);
8b65ee
+	if (!oscap_htable_add(session->oval.results_mapping, original_name, results_file_name)){
8b65ee
+		free(results_file_name);
8b65ee
+	}
8b65ee
+	if (!oscap_htable_add(session->oval.arf_report_mapping, original_name, report_id)) {
8b65ee
+		free(report_id);
8b65ee
+	};
8b65ee
 
8b65ee
 	/* validate OVAL Results */
8b65ee
 	if (session->validate && session->full_validation) {
8b65ee
8b65ee
From 0e35eb691667876d13af6baf0ce4bf73e77cc50c Mon Sep 17 00:00:00 2001
8b65ee
From: =?UTF-8?q?Jan=20=C4=8Cern=C3=BD?= <jcerny@redhat.com>
8b65ee
Date: Mon, 7 Sep 2020 14:14:12 +0200
8b65ee
Subject: [PATCH 2/8] Plug a memory leak
8b65ee
8b65ee
Addressing:
8b65ee
147 bytes in 1 blocks are definitely lost in loss record 220 of 234
8b65ee
   at 0x483A809: malloc (vg_replace_malloc.c:307)
8b65ee
   by 0x489F5DB: oscap_vsprintf (util.c:146)
8b65ee
   by 0x489F6DD: oscap_sprintf (util.c:160)
8b65ee
   by 0x48B9CFB: ds_rds_create_from_dom (rds.c:710)
8b65ee
   by 0x48BA3C1: ds_rds_create_source (rds.c:829)
8b65ee
   by 0x491E83F: xccdf_session_create_arf_source (xccdf_session.c:241)
8b65ee
   by 0x4922496: xccdf_session_export_arf (xccdf_session.c:1630)
8b65ee
   by 0x411110: app_evaluate_xccdf (oscap-xccdf.c:617)
8b65ee
   by 0x40FFF8: oscap_module_call (oscap-tool.c:292)
8b65ee
   by 0x4104C5: oscap_module_process (oscap-tool.c:382)
8b65ee
   by 0x4130A9: main (oscap.c:88)
8b65ee
8b65ee
147 bytes in 1 blocks are definitely lost in loss record 221 of 234
8b65ee
   at 0x483A809: malloc (vg_replace_malloc.c:307)
8b65ee
   by 0x489F5DB: oscap_vsprintf (util.c:146)
8b65ee
   by 0x489F6DD: oscap_sprintf (util.c:160)
8b65ee
   by 0x48B9D17: ds_rds_create_from_dom (rds.c:711)
8b65ee
   by 0x48BA3C1: ds_rds_create_source (rds.c:829)
8b65ee
   by 0x491E83F: xccdf_session_create_arf_source (xccdf_session.c:241)
8b65ee
   by 0x4922496: xccdf_session_export_arf (xccdf_session.c:1630)
8b65ee
   by 0x411110: app_evaluate_xccdf (oscap-xccdf.c:617)
8b65ee
   by 0x40FFF8: oscap_module_call (oscap-tool.c:292)
8b65ee
   by 0x4104C5: oscap_module_process (oscap-tool.c:382)
8b65ee
   by 0x4130A9: main (oscap.c:88)
8b65ee
---
8b65ee
 src/DS/rds.c | 3 +++
8b65ee
 1 file changed, 3 insertions(+)
8b65ee
8b65ee
diff --git a/src/XCCDF/xccdf_session.c b/src/XCCDF/xccdf_session.c
8b65ee
index cc7ac57c56..2272c99d4f 100644
8b65ee
--- a/src/XCCDF/xccdf_session.c
8b65ee
+++ b/src/XCCDF/xccdf_session.c
8b65ee
@@ -1324,8 +1324,10 @@ static int _build_xccdf_result_source(struct xccdf_session *session)
8b65ee
 			if (oscap_source_save_as(stig_result, NULL) != 0) {
8b65ee
 				oscap_seterr(OSCAP_EFAMILY_OSCAP, "Could not save file: %s",
8b65ee
 						oscap_source_readable_origin(stig_result));
8b65ee
+				oscap_source_free(stig_result);
8b65ee
 				return -1;
8b65ee
 			}
8b65ee
+			oscap_source_free(stig_result);
8b65ee
 		}
8b65ee
 
8b65ee
 		/* validate XCCDF Results */
8b65ee
8b65ee
From 47d6e7746a68da1376b6122af101471c64d000ea Mon Sep 17 00:00:00 2001
8b65ee
From: =?UTF-8?q?Jan=20=C4=8Cern=C3=BD?= <jcerny@redhat.com>
8b65ee
Date: Mon, 7 Sep 2020 15:52:41 +0200
8b65ee
Subject: [PATCH 4/8] Plug a memory leak
8b65ee
8b65ee
When the component wasn't registered successfully, we should free the oscap_source structure.
8b65ee
8b65ee
Addressing:
8b65ee
59,044 (56 direct, 58,988 indirect) bytes in 1 blocks are definitely lost in loss record 252 of 252
8b65ee
   at 0x483CAE9: calloc (vg_replace_malloc.c:760)
8b65ee
   by 0x48C0038: oscap_source_new_from_xmlDoc (oscap_source.c:136)
8b65ee
   by 0x48BBF01: ds_sds_register_xmlDoc (sds.c:250)
8b65ee
   by 0x48BBFD5: ds_sds_register_component (sds.c:271)
8b65ee
   by 0x48BC0C5: ds_sds_dump_local_component (sds.c:298)
8b65ee
   by 0x48BC3FD: ds_sds_dump_component_by_href (sds.c:384)
8b65ee
   by 0x48BC6AA: ds_sds_dump_component_ref_as (sds.c:451)
8b65ee
   by 0x48BC969: ds_sds_dump_component_ref_as (sds.c:513)
8b65ee
   by 0x48BCA69: ds_sds_dump_component_ref (sds.c:540)
8b65ee
   by 0x48B7F74: ds_sds_session_register_component_with_dependencies (ds_sds_session.c:308)
8b65ee
   by 0x491FD48: xccdf_session_load_cpe (xccdf_session.c:801)
8b65ee
   by 0x491F43E: xccdf_session_load (xccdf_session.c:594)
8b65ee
---
8b65ee
 src/DS/sds.c | 4 +++-
8b65ee
 1 file changed, 3 insertions(+), 1 deletion(-)
8b65ee
8b65ee
diff --git a/src/DS/sds.c b/src/DS/sds.c
8b65ee
index d901b30dc9..6a4f6847fc 100644
8b65ee
--- a/src/DS/sds.c
8b65ee
+++ b/src/DS/sds.c
8b65ee
@@ -249,7 +249,9 @@ static int ds_sds_register_xmlDoc(struct ds_sds_session *session, xmlDoc* doc, x
8b65ee
 
8b65ee
 	struct oscap_source *component_source = oscap_source_new_from_xmlDoc(new_doc, relative_filepath);
8b65ee
 
8b65ee
-	ds_sds_session_register_component_source(session, relative_filepath, component_source);
8b65ee
+	if (ds_sds_session_register_component_source(session, relative_filepath, component_source) != 0) {
8b65ee
+		oscap_source_free(component_source);
8b65ee
+	}
8b65ee
 	return 0; // TODO: Return value of ds_sds_session_register_component_source(). (commit message)
8b65ee
 }
8b65ee
 
8b65ee
8b65ee