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