summaryrefslogtreecommitdiff
path: root/libelf
diff options
context:
space:
mode:
authorMark Wielaard <mark@klomp.org>2019-04-30 13:00:17 +0200
committerMark Wielaard <mark@klomp.org>2019-05-04 21:31:08 +0200
commit1d8f5d30a92285fd4e7895a1d00587ac487412e3 (patch)
tree4daa1df6e8f87cf7286e3c276e7729fda2fee9a0 /libelf
parent62bed2018232379ac91020137df37afe5e6a5579 (diff)
downloadelfutils-1d8f5d30a92285fd4e7895a1d00587ac487412e3.tar.gz
libelf: If xlate can only convert the ELF note header, just do that.
When we started parsing new style ELF_T_NHDR8 notes we added extra checks on alignment and padding. When those failed we would stop converting and just return the rest of the ELF Note unconverted. In the case were we just had enough data for just the ELF Note header and the destionation and source weren't the same we would then accidentially throw away the Note header conversion we just did. Fix that by indicating we did correctly convert just the header. Adds testcase that compares parsing ELF notes with gelf_getnote and parsing the raw data by hand using elf32_xlatetom using just the Note header and ignoring the (raw) note data. Signed-off-by: Mark Wielaard <mark@klomp.org>
Diffstat (limited to 'libelf')
-rw-r--r--libelf/ChangeLog5
-rw-r--r--libelf/note_xlate.h16
2 files changed, 19 insertions, 2 deletions
diff --git a/libelf/ChangeLog b/libelf/ChangeLog
index d3bdac3d..5eadaf76 100644
--- a/libelf/ChangeLog
+++ b/libelf/ChangeLog
@@ -1,3 +1,8 @@
+2019-04-30 Mark Wielaard <mark@klomp.org>
+
+ * note_xlate.h (elf_cvt_note): Indicate we only translated the note
+ header if we ran out of data by updating len, src and dest.
+
2019-04-01 Mao Han <han_mao@c-sky.com>
* elf.h: Update from glibc.
diff --git a/libelf/note_xlate.h b/libelf/note_xlate.h
index bc9950ff..7e2784b0 100644
--- a/libelf/note_xlate.h
+++ b/libelf/note_xlate.h
@@ -47,13 +47,25 @@ elf_cvt_note (void *dest, const void *src, size_t len, int encode,
note_len += n->n_namesz;
note_len = nhdr8 ? NOTE_ALIGN8 (note_len) : NOTE_ALIGN4 (note_len);
if (note_len > len || note_len < sizeof *n)
- break;
+ {
+ /* Header was translated, nothing else. */
+ len -= sizeof *n;
+ src += sizeof *n;
+ dest += sizeof *n;
+ break;
+ }
/* data as a whole needs to be aligned. */
note_len += n->n_descsz;
note_len = nhdr8 ? NOTE_ALIGN8 (note_len) : NOTE_ALIGN4 (note_len);
if (note_len > len || note_len < sizeof *n)
- break;
+ {
+ /* Header was translated, nothing else. */
+ len -= sizeof *n;
+ src += sizeof *n;
+ dest += sizeof *n;
+ break;
+ }
/* Copy or skip the note data. */
size_t note_data_len = note_len - sizeof *n;