Blob Blame History Raw
From e3d754aad633f2f2ad2735a2eea63f84258fbea7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jan=20=C4=8Cern=C3=BD?= <jcerny@redhat.com>
Date: Mon, 7 Sep 2020 13:57:17 +0200
Subject: [PATCH 1/8] Plug a memory leak

When the key is already present in the hash table the values
are not inserted to the hash table therefore they are not
freed when the hash table is destroyed.

Addressing:
6 bytes in 1 blocks are definitely lost in loss record 2 of 234
   at 0x483A809: malloc (vg_replace_malloc.c:307)
   by 0x489F5DB: oscap_vsprintf (util.c:146)
   by 0x489F6DD: oscap_sprintf (util.c:160)
   by 0x4921E77: _xccdf_session_export_oval_result_file (xccdf_session.c:1493)
   by 0x492209E: _build_oval_result_sources (xccdf_session.c:1538)
   by 0x492210F: xccdf_session_export_oval (xccdf_session.c:1552)
   by 0x410F77: app_evaluate_xccdf (oscap-xccdf.c:592)
   by 0x40FFF8: oscap_module_call (oscap-tool.c:292)
   by 0x4104C5: oscap_module_process (oscap-tool.c:382)
   by 0x4130A9: main (oscap.c:88)

45 bytes in 1 blocks are definitely lost in loss record 124 of 234
   at 0x483A809: malloc (vg_replace_malloc.c:307)
   by 0x52262DE: strdup (in /usr/lib64/libc-2.31.so)
   by 0x491E383: oscap_strdup (util.h:312)
   by 0x4921E97: _xccdf_session_export_oval_result_file (xccdf_session.c:1495)
   by 0x492209E: _build_oval_result_sources (xccdf_session.c:1538)
   by 0x492210F: xccdf_session_export_oval (xccdf_session.c:1552)
   by 0x410F77: app_evaluate_xccdf (oscap-xccdf.c:592)
   by 0x40FFF8: oscap_module_call (oscap-tool.c:292)
   by 0x4104C5: oscap_module_process (oscap-tool.c:382)
   by 0x4130A9: main (oscap.c:88)
---
 src/XCCDF/xccdf_session.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/XCCDF/xccdf_session.c b/src/XCCDF/xccdf_session.c
index 25257e5106..cc7ac57c56 100644
--- a/src/XCCDF/xccdf_session.c
+++ b/src/XCCDF/xccdf_session.c
@@ -1493,8 +1493,12 @@ static char *_xccdf_session_export_oval_result_file(struct xccdf_session *sessio
 	char *report_id = oscap_sprintf("oval%d", counter++);
 	const char *original_name = oval_agent_get_filename(oval_session);
 	char *results_file_name = oscap_strdup(name);
-	oscap_htable_add(session->oval.results_mapping, original_name, results_file_name);
-	oscap_htable_add(session->oval.arf_report_mapping, original_name, report_id);
+	if (!oscap_htable_add(session->oval.results_mapping, original_name, results_file_name)){
+		free(results_file_name);
+	}
+	if (!oscap_htable_add(session->oval.arf_report_mapping, original_name, report_id)) {
+		free(report_id);
+	};
 
 	/* validate OVAL Results */
 	if (session->validate && session->full_validation) {

From 0e35eb691667876d13af6baf0ce4bf73e77cc50c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jan=20=C4=8Cern=C3=BD?= <jcerny@redhat.com>
Date: Mon, 7 Sep 2020 14:14:12 +0200
Subject: [PATCH 2/8] Plug a memory leak

Addressing:
147 bytes in 1 blocks are definitely lost in loss record 220 of 234
   at 0x483A809: malloc (vg_replace_malloc.c:307)
   by 0x489F5DB: oscap_vsprintf (util.c:146)
   by 0x489F6DD: oscap_sprintf (util.c:160)
   by 0x48B9CFB: ds_rds_create_from_dom (rds.c:710)
   by 0x48BA3C1: ds_rds_create_source (rds.c:829)
   by 0x491E83F: xccdf_session_create_arf_source (xccdf_session.c:241)
   by 0x4922496: xccdf_session_export_arf (xccdf_session.c:1630)
   by 0x411110: app_evaluate_xccdf (oscap-xccdf.c:617)
   by 0x40FFF8: oscap_module_call (oscap-tool.c:292)
   by 0x4104C5: oscap_module_process (oscap-tool.c:382)
   by 0x4130A9: main (oscap.c:88)

147 bytes in 1 blocks are definitely lost in loss record 221 of 234
   at 0x483A809: malloc (vg_replace_malloc.c:307)
   by 0x489F5DB: oscap_vsprintf (util.c:146)
   by 0x489F6DD: oscap_sprintf (util.c:160)
   by 0x48B9D17: ds_rds_create_from_dom (rds.c:711)
   by 0x48BA3C1: ds_rds_create_source (rds.c:829)
   by 0x491E83F: xccdf_session_create_arf_source (xccdf_session.c:241)
   by 0x4922496: xccdf_session_export_arf (xccdf_session.c:1630)
   by 0x411110: app_evaluate_xccdf (oscap-xccdf.c:617)
   by 0x40FFF8: oscap_module_call (oscap-tool.c:292)
   by 0x4104C5: oscap_module_process (oscap-tool.c:382)
   by 0x4130A9: main (oscap.c:88)
---
 src/DS/rds.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/XCCDF/xccdf_session.c b/src/XCCDF/xccdf_session.c
index cc7ac57c56..2272c99d4f 100644
--- a/src/XCCDF/xccdf_session.c
+++ b/src/XCCDF/xccdf_session.c
@@ -1324,8 +1324,10 @@ static int _build_xccdf_result_source(struct xccdf_session *session)
 			if (oscap_source_save_as(stig_result, NULL) != 0) {
 				oscap_seterr(OSCAP_EFAMILY_OSCAP, "Could not save file: %s",
 						oscap_source_readable_origin(stig_result));
+				oscap_source_free(stig_result);
 				return -1;
 			}
+			oscap_source_free(stig_result);
 		}
 
 		/* validate XCCDF Results */

From 47d6e7746a68da1376b6122af101471c64d000ea Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jan=20=C4=8Cern=C3=BD?= <jcerny@redhat.com>
Date: Mon, 7 Sep 2020 15:52:41 +0200
Subject: [PATCH 4/8] Plug a memory leak

When the component wasn't registered successfully, we should free the oscap_source structure.

Addressing:
59,044 (56 direct, 58,988 indirect) bytes in 1 blocks are definitely lost in loss record 252 of 252
   at 0x483CAE9: calloc (vg_replace_malloc.c:760)
   by 0x48C0038: oscap_source_new_from_xmlDoc (oscap_source.c:136)
   by 0x48BBF01: ds_sds_register_xmlDoc (sds.c:250)
   by 0x48BBFD5: ds_sds_register_component (sds.c:271)
   by 0x48BC0C5: ds_sds_dump_local_component (sds.c:298)
   by 0x48BC3FD: ds_sds_dump_component_by_href (sds.c:384)
   by 0x48BC6AA: ds_sds_dump_component_ref_as (sds.c:451)
   by 0x48BC969: ds_sds_dump_component_ref_as (sds.c:513)
   by 0x48BCA69: ds_sds_dump_component_ref (sds.c:540)
   by 0x48B7F74: ds_sds_session_register_component_with_dependencies (ds_sds_session.c:308)
   by 0x491FD48: xccdf_session_load_cpe (xccdf_session.c:801)
   by 0x491F43E: xccdf_session_load (xccdf_session.c:594)
---
 src/DS/sds.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/DS/sds.c b/src/DS/sds.c
index d901b30dc9..6a4f6847fc 100644
--- a/src/DS/sds.c
+++ b/src/DS/sds.c
@@ -249,7 +249,9 @@ static int ds_sds_register_xmlDoc(struct ds_sds_session *session, xmlDoc* doc, x
 
 	struct oscap_source *component_source = oscap_source_new_from_xmlDoc(new_doc, relative_filepath);
 
-	ds_sds_session_register_component_source(session, relative_filepath, component_source);
+	if (ds_sds_session_register_component_source(session, relative_filepath, component_source) != 0) {
+		oscap_source_free(component_source);
+	}
 	return 0; // TODO: Return value of ds_sds_session_register_component_source(). (commit message)
 }