[binutils-gdb] Fix undefined behavior, don't pass NULL to fwrite
Simon Marchi
simark@sourceware.org
Fri Oct 5 03:01:00 GMT 2018
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=1f88d0c87c37d3a15fa6376335e8b0d1c79d85aa
commit 1f88d0c87c37d3a15fa6376335e8b0d1c79d85aa
Author: Simon Marchi <simon.marchi@ericsson.com>
Date: Thu Oct 4 22:43:27 2018 -0400
Fix undefined behavior, don't pass NULL to fwrite
If a vector that we try to write using file_write is empty, we may end
up passing NULL to fwrite, which triggers UBSan:
.../gdb/dwarf-index-write.c:73:14: runtime error: null pointer passed as argument 1, which is declared to never be null
Avoid it by skipping the write if the vector is empty.
gdb/ChangeLog:
* dwarf-index-write.c (file_write): Don't write if the vector is
empty.
Diff:
---
gdb/ChangeLog | 5 +++++
gdb/dwarf-index-write.c | 3 ++-
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 126deb7..0e5a3f4 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2018-10-04 Simon Marchi <simon.marchi@ericsson.com>
+
+ * dwarf-index-write.c (file_write): Don't write if the vector is
+ empty.
+
2018-10-05 Tom de Vries <tdevries@suse.de>
* python/py-progspace.c (pspy_solib_name): Fix type mismatch in
diff --git a/gdb/dwarf-index-write.c b/gdb/dwarf-index-write.c
index 2520321..d4585af 100644
--- a/gdb/dwarf-index-write.c
+++ b/gdb/dwarf-index-write.c
@@ -80,7 +80,8 @@ template<typename Elem, typename Alloc>
static void
file_write (FILE *file, const std::vector<Elem, Alloc> &vec)
{
- file_write (file, vec.data (), vec.size () * sizeof (vec[0]));
+ if (!vec.empty ())
+ file_write (file, vec.data (), vec.size () * sizeof (vec[0]));
}
/* In-memory buffer to prepare data to be written later to a file. */
More information about the Gdb-cvs
mailing list