Blame SOURCES/0001-Fix-additional-covscan-warnings.patch

0f2056
From 949c391537a588bd7359a00a716359e37afcd4da Mon Sep 17 00:00:00 2001
0f2056
From: =?UTF-8?q?Ale=C5=A1=20Mat=C4=9Bj?= <amatej@redhat.com>
0f2056
Date: Mon, 19 Jul 2021 09:56:31 +0200
0f2056
Subject: [PATCH] Fix additional covscan warnings
0f2056
0f2056
- check we actually got a filename in xml parsers and in decompression
0f2056
  function
0f2056
- use g_malloc0 as we do in other places (it also takes care of checking
0f2056
  if allocation was successful)
0f2056
---
0f2056
 src/dumper_thread.c        | 2 +-
0f2056
 src/misc.c                 | 6 ++++++
0f2056
 src/xml_parser_filelists.c | 5 +++++
0f2056
 src/xml_parser_primary.c   | 5 +++++
0f2056
 4 files changed, 17 insertions(+), 1 deletion(-)
0f2056
0f2056
diff --git a/src/dumper_thread.c b/src/dumper_thread.c
0f2056
index 119f3bd8..ea10c774 100644
0f2056
--- a/src/dumper_thread.c
0f2056
+++ b/src/dumper_thread.c
0f2056
@@ -562,7 +562,7 @@ cr_dumper_thread(gpointer data, gpointer user_data)
0f2056
         //  * this isn't the last task
0f2056
         // Then: save the task to the buffer
0f2056
 
0f2056
-        struct BufferedTask *buf_task = malloc(sizeof(struct BufferedTask));
0f2056
+        struct BufferedTask *buf_task = g_malloc0(sizeof(struct BufferedTask));
0f2056
         buf_task->id  = task->id;
0f2056
         buf_task->res = res;
0f2056
         buf_task->pkg = pkg;
0f2056
diff --git a/src/misc.c b/src/misc.c
0f2056
index adbc4af0..b59f304a 100644
0f2056
--- a/src/misc.c
0f2056
+++ b/src/misc.c
0f2056
@@ -622,6 +622,12 @@ cr_decompress_file_with_stat(const char *src,
0f2056
 
0f2056
     if (!in_dst || g_str_has_suffix(in_dst, "/")) {
0f2056
         char *filename = cr_get_filename(src);
0f2056
+        if (!filename) {
0f2056
+            g_debug("%s: Cannot get filename from: %s", __func__, src);
0f2056
+            g_set_error(err, ERR_DOMAIN, CRE_NOFILE,
0f2056
+                        "Cannot get filename from: %s", src);
0f2056
+            return CRE_NOFILE;
0f2056
+        }
0f2056
         if (g_str_has_suffix(filename, c_suffix)) {
0f2056
             filename = g_strndup(filename, strlen(filename) - strlen(c_suffix));
0f2056
         } else {
0f2056
diff --git a/src/xml_parser_filelists.c b/src/xml_parser_filelists.c
0f2056
index f4fe6c09..86ab6c80 100644
0f2056
--- a/src/xml_parser_filelists.c
0f2056
+++ b/src/xml_parser_filelists.c
0f2056
@@ -259,6 +259,11 @@ cr_end_handler(void *pdata, G_GNUC_UNUSED const xmlChar *element)
0f2056
         cr_PackageFile *pkg_file = cr_package_file_new();
0f2056
         pkg_file->name = cr_safe_string_chunk_insert(pd->pkg->chunk,
0f2056
                                                 cr_get_filename(pd->content));
0f2056
+        if (!pkg_file->name) {
0f2056
+            g_set_error(&pd->err, ERR_DOMAIN, ERR_CODE_XML,
0f2056
+                        "Invalid <file> element: %s", pd->content);
0f2056
+            break;
0f2056
+        }
0f2056
         pd->content[pd->lcontent - strlen(pkg_file->name)] = '\0';
0f2056
         pkg_file->path = cr_safe_string_chunk_insert_const(pd->pkg->chunk,
0f2056
                                                            pd->content);
0f2056
diff --git a/src/xml_parser_primary.c b/src/xml_parser_primary.c
0f2056
index 86e20519..e83eb044 100644
0f2056
--- a/src/xml_parser_primary.c
0f2056
+++ b/src/xml_parser_primary.c
0f2056
@@ -633,6 +633,11 @@ cr_end_handler(void *pdata, G_GNUC_UNUSED const xmlChar *element)
0f2056
         cr_PackageFile *pkg_file = cr_package_file_new();
0f2056
         pkg_file->name = cr_safe_string_chunk_insert(pd->pkg->chunk,
0f2056
                                                 cr_get_filename(pd->content));
0f2056
+        if (!pkg_file->name) {
0f2056
+            g_set_error(&pd->err, ERR_DOMAIN, ERR_CODE_XML,
0f2056
+                        "Invalid <file> element: %s", pd->content);
0f2056
+            break;
0f2056
+        }
0f2056
         pd->content[pd->lcontent - strlen(pkg_file->name)] = '\0';
0f2056
         pkg_file->path = cr_safe_string_chunk_insert_const(pd->pkg->chunk,
0f2056
                                                            pd->content);