This is the mail archive of the elfutils-devel@sourceware.org mailing list for the elfutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] libdwfl: Fix wrong type to make gcc -fsanitize=undefined happy.


gcc -fsanitize=undefined would warn about calling dwfl_error accessing
the error string array: elfutils/libdwfl/dwfl_error.c:156:60:
	runtime error: index 385 out of bounds for type 'char [9]'

This is because it thought we went beyond error string zero "no error",
which is indeed 9 chars. "Correct" the type of the pointer to make
ubsan happy.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
---
 libdwfl/ChangeLog    | 4 ++++
 libdwfl/dwfl_error.c | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index d4cd3f5..90c0a04 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,3 +1,7 @@
+2015-04-21  Mark Wielaard  <mjw@redhat.com>
+
+	* dwfl_error.c (msgstr): Define as const char *.
+
 2015-04-02  Mark Wielaard  <mjw@redhat.com>
 
 	* segment.c (insert): Check correct number of lookup_elts.
diff --git a/libdwfl/dwfl_error.c b/libdwfl/dwfl_error.c
index d9ca9e7..c3648c0 100644
--- a/libdwfl/dwfl_error.c
+++ b/libdwfl/dwfl_error.c
@@ -65,7 +65,7 @@ static const struct msgtable
   DWFL_ERRORS
 #undef	DWFL_ERROR
   };
-#define msgstr (&msgtable.msg_NOERROR[0])
+#define msgstr ((const char *) &msgtable)
 
 static const uint_fast16_t msgidx[] =
 {
-- 
2.1.0


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]