From b0b58c5e0b34e54194aa042f2310af58ee7de603 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Fri, 24 Mar 2017 14:10:26 +0100 Subject: Use the empty string for note names with zero size (without any data). ELF notes can have a zero sized name. In which case there is no data at all (so also no zero terminator). Make sure to use the empty string for such notes if the code does not otherwise explicitly check n_namesz. https://sourceware.org/bugzilla/show_bug.cgi?id=21300 Signed-off-by: Mark Wielaard --- src/elfcmp.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/elfcmp.c') diff --git a/src/elfcmp.c b/src/elfcmp.c index 7673cf21..50464207 100644 --- a/src/elfcmp.c +++ b/src/elfcmp.c @@ -419,7 +419,8 @@ main (int argc, char *argv[]) && (off1 = gelf_getnote (data1, off1, ¬e1, &name_offset, &desc_offset)) > 0) { - const char *name1 = data1->d_buf + name_offset; + const char *name1 = (note1.n_namesz == 0 + ? "" : data1->d_buf + name_offset); const void *desc1 = data1->d_buf + desc_offset; if (off2 >= data2->d_size) { @@ -435,7 +436,8 @@ main (int argc, char *argv[]) error (2, 0, gettext ("\ cannot read note section [%zu] '%s' in '%s': %s"), elf_ndxscn (scn2), sname2, fname2, elf_errmsg (-1)); - const char *name2 = data2->d_buf + name_offset; + const char *name2 = (note2.n_namesz == 0 + ? "" : data2->d_buf + name_offset); const void *desc2 = data2->d_buf + desc_offset; if (note1.n_namesz != note2.n_namesz -- cgit v1.2.3