mfabik / rpms / satyr

Forked from rpms/satyr 3 years ago
Clone

Blame SOURCES/satyr-0.13-Fix-defects-found-by-coverity.patch

1275dc
From 481ac50e3e9ad53e4f07dce04facfaef5a2cdcfd Mon Sep 17 00:00:00 2001
1275dc
From: Martin Milata <mmilata@redhat.com>
1275dc
Date: Thu, 5 Mar 2015 14:08:15 +0100
1275dc
Subject: [PATCH] Fix defects found by coverity
1275dc
1275dc
Resolves: #1336390
1275dc
1275dc
Signed-off-by: Martin Milata <mmilata@redhat.com>
1275dc
1275dc
Conflicts:
1275dc
	lib/abrt.c
1275dc
---
1275dc
 lib/core_stacktrace.c      |  8 ++++++++
1275dc
 lib/core_unwind.c          |  6 ++++--
1275dc
 lib/java_frame.c           |  3 +++
1275dc
 lib/koops_stacktrace.c     |  3 +++
1275dc
 lib/python_frame.c         | 26 ++++++++++++++------------
1275dc
 lib/rpm.c                  |  4 +++-
1275dc
 lib/utils.c                |  1 +
1275dc
 python/py_gdb_stacktrace.c |  8 ++++++++
1275dc
 satyr.c                    |  3 +++
1275dc
 9 files changed, 47 insertions(+), 15 deletions(-)
1275dc
1275dc
diff --git a/lib/core_stacktrace.c b/lib/core_stacktrace.c
1275dc
index f7fd369..aeb97e4 100644
1275dc
--- a/lib/core_stacktrace.c
1275dc
+++ b/lib/core_stacktrace.c
1275dc
@@ -192,7 +192,10 @@ sr_core_stacktrace_from_json(struct sr_json_value *root,
1275dc
             if (crash_thread)
1275dc
             {
1275dc
                 if (!JSON_CHECK_TYPE(crash_thread, SR_JSON_BOOLEAN, "crash_thread"))
1275dc
+                {
1275dc
+                    sr_core_thread_free(thread);
1275dc
                     goto fail;
1275dc
+                }
1275dc
 
1275dc
                 if (crash_thread->u.boolean)
1275dc
                     result->crash_thread = thread;
1275dc
@@ -296,6 +299,7 @@ sr_core_stacktrace_create(const char *gdb_stacktrace_text,
1275dc
     {
1275dc
         warn("Unable to parse unstrip output.");
1275dc
 
1275dc
+        sr_gdb_stacktrace_free(gdb_stacktrace);
1275dc
         return NULL;
1275dc
     }
1275dc
 
1275dc
@@ -332,6 +336,8 @@ sr_core_stacktrace_create(const char *gdb_stacktrace_text,
1275dc
                 core_frame->function_name =
1275dc
                     sr_strdup(gdb_frame->function_name);
1275dc
             }
1275dc
+
1275dc
+            core_thread->frames = sr_core_frame_append(core_thread->frames, core_frame);
1275dc
         }
1275dc
 
1275dc
         core_stacktrace->threads =
1275dc
@@ -341,6 +347,8 @@ sr_core_stacktrace_create(const char *gdb_stacktrace_text,
1275dc
         gdb_thread = gdb_thread->next;
1275dc
     }
1275dc
 
1275dc
+    sr_unstrip_free(unstrip);
1275dc
+    sr_gdb_stacktrace_free(gdb_stacktrace);
1275dc
     return core_stacktrace;
1275dc
 }
1275dc
 
1275dc
diff --git a/lib/core_unwind.c b/lib/core_unwind.c
1275dc
index c30f9db..b8c0235 100644
1275dc
--- a/lib/core_unwind.c
1275dc
+++ b/lib/core_unwind.c
1275dc
@@ -127,6 +127,7 @@ find_elf_core (Dwfl_Module *mod, void **userdata, const char *modname,
1275dc
         {
1275dc
             warn("Unable to open executable '%s': %s", executable_file,
1275dc
                  elf_errmsg(-1));
1275dc
+            close(fd);
1275dc
             return -1;
1275dc
         }
1275dc
 
1275dc
@@ -399,9 +400,10 @@ struct sr_core_stacktrace *
1275dc
 sr_core_stacktrace_from_gdb(const char *gdb_output, const char *core_file,
1275dc
                             const char *exe_file, char **error_msg)
1275dc
 {
1275dc
+    /* I'm not going to rewrite it now since the function is not being used. */
1275dc
+    assert(error_msg);
1275dc
     /* Initialize error_msg to 'no error'. */
1275dc
-    if (error_msg)
1275dc
-        *error_msg = NULL;
1275dc
+    *error_msg = NULL;
1275dc
 
1275dc
     struct core_handle *ch = open_coredump(core_file, exe_file, error_msg);
1275dc
     if (*error_msg)
1275dc
diff --git a/lib/java_frame.c b/lib/java_frame.c
1275dc
index ee97572..d03f86a 100644
1275dc
--- a/lib/java_frame.c
1275dc
+++ b/lib/java_frame.c
1275dc
@@ -359,7 +359,10 @@ sr_java_frame_parse_exception(const char **input,
1275dc
         if (exception->next == NULL)
1275dc
             exception->next = parsed;
1275dc
         else
1275dc
+        {
1275dc
+            assert(frame);
1275dc
             frame->next = parsed;
1275dc
+        }
1275dc
 
1275dc
         frame = parsed;
1275dc
     }
1275dc
diff --git a/lib/koops_stacktrace.c b/lib/koops_stacktrace.c
1275dc
index 611c7d1..01baa79 100644
1275dc
--- a/lib/koops_stacktrace.c
1275dc
+++ b/lib/koops_stacktrace.c
1275dc
@@ -506,7 +506,10 @@ taint_flags_to_json(struct sr_koops_stacktrace *stacktrace)
1275dc
     }
1275dc
 
1275dc
     if (strbuf->len == 0)
1275dc
+    {
1275dc
+        sr_strbuf_free(strbuf);
1275dc
         return sr_strdup("[]");
1275dc
+    }
1275dc
 
1275dc
     sr_strbuf_append_char(strbuf, ']');
1275dc
     char *result = sr_strbuf_free_nobuf(strbuf);
1275dc
diff --git a/lib/python_frame.c b/lib/python_frame.c
1275dc
index b0540fe..4b4be8a 100644
1275dc
--- a/lib/python_frame.c
1275dc
+++ b/lib/python_frame.c
1275dc
@@ -220,11 +220,10 @@ sr_python_frame_parse(const char **input,
1275dc
     /* Parse file name */
1275dc
     if (!sr_parse_char_cspan(&local_input, "\"", &frame->file_name))
1275dc
     {
1275dc
-        sr_python_frame_free(frame);
1275dc
         location->message = sr_asprintf("Unable to find the '\"' character "
1275dc
                 "identifying the beginning of file name.");
1275dc
 
1275dc
-        return NULL;
1275dc
+        goto fail;
1275dc
     }
1275dc
 
1275dc
     if (strlen(frame->file_name) > 0 &&
1275dc
@@ -243,7 +242,7 @@ sr_python_frame_parse(const char **input,
1275dc
     if (0 == sr_skip_string(&local_input, "\", line "))
1275dc
     {
1275dc
         location->message = sr_asprintf("Line separator not found.");
1275dc
-        return NULL;
1275dc
+        goto fail;
1275dc
     }
1275dc
 
1275dc
     location->column += strlen("\", line ");
1275dc
@@ -253,7 +252,7 @@ sr_python_frame_parse(const char **input,
1275dc
     if (0 == length)
1275dc
     {
1275dc
         location->message = sr_asprintf("Line number not found.");
1275dc
-        return NULL;
1275dc
+        goto fail;
1275dc
     }
1275dc
 
1275dc
     location->column += length;
1275dc
@@ -263,7 +262,7 @@ sr_python_frame_parse(const char **input,
1275dc
         if (local_input[0] != '\n')
1275dc
         {
1275dc
             location->message = sr_asprintf("Function name separator not found.");
1275dc
-            return NULL;
1275dc
+            goto fail;
1275dc
         }
1275dc
 
1275dc
         /* The last frame of SyntaxError stack trace does not have
1275dc
@@ -280,11 +279,10 @@ sr_python_frame_parse(const char **input,
1275dc
         /* Parse function name */
1275dc
         if (!sr_parse_char_cspan(&local_input, "\n", &frame->function_name))
1275dc
         {
1275dc
-            sr_python_frame_free(frame);
1275dc
             location->message = sr_asprintf("Unable to find the newline character "
1275dc
                     "identifying the end of function name.");
1275dc
 
1275dc
-            return NULL;
1275dc
+            goto fail;
1275dc
         }
1275dc
 
1275dc
         location->column += strlen(frame->function_name);
1275dc
@@ -301,19 +299,23 @@ sr_python_frame_parse(const char **input,
1275dc
         }
1275dc
     }
1275dc
 
1275dc
-    sr_skip_char(&local_input, '\n');
1275dc
-    sr_location_add(location, 1, 0);
1275dc
+    if (sr_skip_char(&local_input, '\n'))
1275dc
+        sr_location_add(location, 1, 0);
1275dc
 
1275dc
     /* Parse source code line (optional). */
1275dc
     if (4 == sr_skip_string(&local_input, "    "))
1275dc
     {
1275dc
-        sr_parse_char_cspan(&local_input, "\n", &frame->line_contents);
1275dc
-        sr_skip_char(&local_input, '\n');
1275dc
-        sr_location_add(location, 1, 0);
1275dc
+        if (sr_parse_char_cspan(&local_input, "\n", &frame->line_contents)
1275dc
+                && sr_skip_char(&local_input, '\n'))
1275dc
+            sr_location_add(location, 1, 0);
1275dc
     }
1275dc
 
1275dc
     *input = local_input;
1275dc
     return frame;
1275dc
+
1275dc
+fail:
1275dc
+    sr_python_frame_free(frame);
1275dc
+    return NULL;
1275dc
 }
1275dc
 
1275dc
 char *
1275dc
diff --git a/lib/rpm.c b/lib/rpm.c
1275dc
index f8f1fa6..920e145 100644
1275dc
--- a/lib/rpm.c
1275dc
+++ b/lib/rpm.c
1275dc
@@ -199,7 +199,9 @@ sr_rpm_package_sort(struct sr_rpm_package *packages)
1275dc
             array[loop]->next = NULL;
1275dc
     }
1275dc
 
1275dc
-    return array[0];
1275dc
+    struct sr_rpm_package *result = array[0];
1275dc
+    free(array);
1275dc
+    return result;
1275dc
 }
1275dc
 
1275dc
 static struct sr_rpm_package *
1275dc
diff --git a/lib/utils.c b/lib/utils.c
1275dc
index fa3c0a0..bdafaa7 100644
1275dc
--- a/lib/utils.c
1275dc
+++ b/lib/utils.c
1275dc
@@ -354,6 +354,7 @@ sr_string_to_file(const char *filename,
1275dc
                                      filename,
1275dc
                                      error);
1275dc
 
1275dc
+        close(fd);
1275dc
         return false;
1275dc
     }
1275dc
 
1275dc
diff --git a/python/py_gdb_stacktrace.c b/python/py_gdb_stacktrace.c
1275dc
index c799e06..5ed3533 100644
1275dc
--- a/python/py_gdb_stacktrace.c
1275dc
+++ b/python/py_gdb_stacktrace.c
1275dc
@@ -7,6 +7,7 @@
1275dc
 #include "strbuf.h"
1275dc
 #include "gdb/stacktrace.h"
1275dc
 #include "gdb/thread.h"
1275dc
+#include "gdb/frame.h"
1275dc
 #include "gdb/sharedlib.h"
1275dc
 #include "location.h"
1275dc
 #include "normalize.h"
1275dc
@@ -408,13 +409,20 @@ sr_py_gdb_stacktrace_find_crash_frame(PyObject *self, PyObject *args)
1275dc
         PyObject_New(struct sr_py_gdb_frame, &sr_py_gdb_frame_type);
1275dc
 
1275dc
     if (!result)
1275dc
+    {
1275dc
+        sr_gdb_frame_free(frame);
1275dc
         return PyErr_NoMemory();
1275dc
+    }
1275dc
 
1275dc
     result->frame = frame;
1275dc
     this->crashframe = result;
1275dc
 
1275dc
     if (stacktrace_rebuild_thread_python_list(this) < 0)
1275dc
+    {
1275dc
+        sr_gdb_frame_free(frame);
1275dc
+        Py_DECREF(result);
1275dc
         return NULL;
1275dc
+    }
1275dc
 
1275dc
     return (PyObject *)result;
1275dc
 }
1275dc
diff --git a/satyr.c b/satyr.c
1275dc
index 6e1ed28..44bf869 100644
1275dc
--- a/satyr.c
1275dc
+++ b/satyr.c
1275dc
@@ -210,6 +210,9 @@ debug_normalize(int argc, char **argv)
1275dc
     struct sr_strbuf *strbuf = sr_strbuf_new();
1275dc
     sr_gdb_thread_append_to_str(thread, strbuf, false);
1275dc
     puts(strbuf->buf);
1275dc
+
1275dc
+    free(text);
1275dc
+    sr_strbuf_free(strbuf);
1275dc
 }
1275dc
 
1275dc
 static void
1275dc
-- 
1275dc
1.8.3.1
1275dc