Blame SOURCES/satyr-0.13-static-analyzer-bugs.patch

f499a8
From 5aab1d42916b93e593db632479a800b1de05d169 Mon Sep 17 00:00:00 2001
f499a8
From: Martin Milata <mmilata@redhat.com>
f499a8
Date: Mon, 17 Feb 2014 12:28:04 +0100
f499a8
Subject: [SATYR PATCH 1/6] Fix minor issues found by static analyzers
f499a8
f499a8
Avoid possible NULL dereferences of error_msg
f499a8
f499a8
Fixes #155.
f499a8
f499a8
Signed-off-by: Martin Milata <mmilata@redhat.com>
f499a8
Signed-off-by: Jakub Filak <jfilak@redhat.com>
f499a8
f499a8
Fix insecure string formatting
f499a8
f499a8
core_unwind_elfutils.c: In function 'sr_parse_coredump':
f499a8
core_unwind_elfutils.c:169:13: error: format not a string literal and no format arguments [-Werror=format-security]
f499a8
             set_error(thread_arg.error_msg);
f499a8
             ^
f499a8
f499a8
Signed-off-by: Martin Milata <mmilata@redhat.com>
f499a8
---
f499a8
 lib/Makefile.am             |  2 +-
f499a8
 lib/core_unwind.c           |  5 +++--
f499a8
 lib/core_unwind_elfutils.c  | 27 +++++++++++++--------------
f499a8
 lib/core_unwind_libunwind.c |  2 +-
f499a8
 4 files changed, 18 insertions(+), 18 deletions(-)
f499a8
f499a8
diff --git a/lib/Makefile.am b/lib/Makefile.am
f499a8
index 73fffe2..f798347 100644
f499a8
--- a/lib/Makefile.am
f499a8
+++ b/lib/Makefile.am
f499a8
@@ -62,7 +62,7 @@ libsatyr_conv_la_SOURCES = \
f499a8
 	unstrip.c \
f499a8
 	utils.c
f499a8
 
f499a8
-libsatyr_conv_la_CFLAGS = -Wall -std=gnu99 -D_GNU_SOURCE -I$(top_srcdir)/include $(GLIB_CFLAGS)
f499a8
+libsatyr_conv_la_CFLAGS = -Wall -Wformat=2 -std=gnu99 -D_GNU_SOURCE -I$(top_srcdir)/include $(GLIB_CFLAGS)
f499a8
 libsatyr_conv_la_LDFLAGS = $(GLIB_LIBS)
f499a8
 
f499a8
 if HAVE_LIBOPCODES
f499a8
diff --git a/lib/core_unwind.c b/lib/core_unwind.c
f499a8
index 7910254..8b7cc22 100644
f499a8
--- a/lib/core_unwind.c
f499a8
+++ b/lib/core_unwind.c
f499a8
@@ -227,9 +227,10 @@ open_coredump(const char *elf_file, const char *exe_file, char **error_msg)
f499a8
     }
f499a8
     ch->segments = head;
f499a8
 
f499a8
-    if (!*error_msg && !head)
f499a8
+    if (!head)
f499a8
     {
f499a8
-        set_error("No segments found in coredump '%s'", elf_file);
f499a8
+        if (error_msg && !*error_msg)
f499a8
+            set_error("No segments found in coredump '%s'", elf_file);
f499a8
         goto fail_dwfl;
f499a8
     }
f499a8
 
f499a8
diff --git a/lib/core_unwind_elfutils.c b/lib/core_unwind_elfutils.c
f499a8
index a8d8b3f..6b904c7 100644
f499a8
--- a/lib/core_unwind_elfutils.c
f499a8
+++ b/lib/core_unwind_elfutils.c
f499a8
@@ -137,20 +137,20 @@ sr_parse_coredump(const char *core_file,
f499a8
         *error_msg = NULL;
f499a8
 
f499a8
     struct core_handle *ch = open_coredump(core_file, exe_file, error_msg);
f499a8
-    if (*error_msg)
f499a8
-        return NULL;
f499a8
+    if (!ch)
f499a8
+        goto fail;
f499a8
 
f499a8
     if (dwfl_core_file_attach(ch->dwfl, ch->eh) < 0)
f499a8
     {
f499a8
         set_error_dwfl("dwfl_core_file_attach");
f499a8
-        goto fail_destroy_handle;
f499a8
+        goto fail;
f499a8
     }
f499a8
 
f499a8
     stacktrace = sr_core_stacktrace_new();
f499a8
     if (!stacktrace)
f499a8
     {
f499a8
         set_error("Failed to initialize stacktrace memory");
f499a8
-        goto fail_destroy_handle;
f499a8
+        goto fail;
f499a8
     }
f499a8
 
f499a8
     struct thread_callback_arg thread_arg =
f499a8
@@ -165,11 +165,16 @@ sr_parse_coredump(const char *core_file,
f499a8
         if (ret == -1)
f499a8
             set_error_dwfl("dwfl_getthreads");
f499a8
         else if (ret == DWARF_CB_ABORT)
f499a8
-            *error_msg = thread_arg.error_msg;
f499a8
+        {
f499a8
+            set_error("%s", thread_arg.error_msg);
f499a8
+            free(thread_arg.error_msg);
f499a8
+        }
f499a8
         else
f499a8
-            *error_msg = sr_strdup("Unknown error in dwfl_getthreads");
f499a8
+            set_error("Unknown error in dwfl_getthreads");
f499a8
 
f499a8
-        goto fail_destroy_trace;
f499a8
+        sr_core_stacktrace_free(stacktrace);
f499a8
+        stacktrace = NULL;
f499a8
+        goto fail;
f499a8
     }
f499a8
 
f499a8
     stacktrace->executable = sr_strdup(exe_file);
f499a8
@@ -177,13 +182,7 @@ sr_parse_coredump(const char *core_file,
f499a8
     /* FIXME: is this the best we can do? */
f499a8
     stacktrace->crash_thread = stacktrace->threads;
f499a8
 
f499a8
-fail_destroy_trace:
f499a8
-    if (*error_msg)
f499a8
-    {
f499a8
-        sr_core_stacktrace_free(stacktrace);
f499a8
-        stacktrace = NULL;
f499a8
-    }
f499a8
-fail_destroy_handle:
f499a8
+fail:
f499a8
     core_handle_free(ch);
f499a8
     return stacktrace;
f499a8
 }
f499a8
diff --git a/lib/core_unwind_libunwind.c b/lib/core_unwind_libunwind.c
f499a8
index 966a5b9..b45e2ad 100644
f499a8
--- a/lib/core_unwind_libunwind.c
f499a8
+++ b/lib/core_unwind_libunwind.c
f499a8
@@ -99,7 +99,7 @@ unwind_thread(struct UCD_info *ui,
f499a8
         }
f499a8
     }
f499a8
 
f499a8
-    if (!error_msg && !trace)
f499a8
+    if (error_msg && !*error_msg && !trace)
f499a8
     {
f499a8
         set_error("No frames found for thread %d", thread_no);
f499a8
     }
f499a8
-- 
f499a8
1.9.3
f499a8