mfabik / rpms / satyr

Forked from rpms/satyr 3 years ago
Clone

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

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