Skip to contentSkip to conversation

dump: fix note_name_equal()

PATCH In review Marc-André Lureau 3 participants 3 messages Dec 12, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dump: fix note_name_equal()

Use the function argument "name" instead of hardcoded "VMCOREINFO". All callers use "VMCOREINFO" as argument, so this isn't an exposed bug, thankfully.

Simplify a little bit the code while touching this.

---
 dump.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
dump.c +1 -6
index d4a8c942eb..e9dfed060a 100644
@@ -788,12 +788,7 @@ static bool note_name_equal(DumpState *s,
     get_note_sizes(s, note, &head_size, &name_size, NULL);
     head_size = ROUND_UP(head_size, 4);
 
-    if (name_size != len ||
-        memcmp(note + head_size, "VMCOREINFO", len)) {
-        return false;
-    }
-
-    return true;
+    return name_size == len && memcmp(note + head_size, name, len) == 0;
 }
 
 /* write common header, sub header and elf note to vmcore */
Signature · 1 line
2.15.1.355.g36791d7216
Reviewed-by on v1 1/1
#1 lore raw
Quoted 22 lines · Marc-André Lureau

Use the function argument "name" instead of hardcoded "VMCOREINFO". All callers use "VMCOREINFO" as argument, so this isn't an exposed bug, thankfully.

Simplify a little bit the code while touching this.

---
 dump.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
dump.c +0 -0
index d4a8c942eb..e9dfed060a 100644
@@ -788,12 +788,7 @@ static bool note_name_equal(DumpState *s,
     get_note_sizes(s, note, &head_size, &name_size, NULL);
     head_size = ROUND_UP(head_size, 4);
 

dump.c static bool note_name_equal(DumpState *s, · line 794

Quoted 10 lines
dump.c +1 -6
-    if (name_size != len ||
-        memcmp(note + head_size, "VMCOREINFO", len)) {
-        return false;
-    }
-
-    return true;
+    return name_size == len && memcmp(note + head_size, name, len) == 0;
 }
 
 /* write common header, sub header and elf note to vmcore */
Reviewed-by on v1 1/1
#2 lore raw
In reply to Marc-André Lureau
Quoted 34 lines · Marc-André Lureau

Use the function argument "name" instead of hardcoded "VMCOREINFO". All callers use "VMCOREINFO" as argument, so this isn't an exposed bug, thankfully.

Simplify a little bit the code while touching this.

---
 dump.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
dump.c +1 -6
index d4a8c942eb..e9dfed060a 100644
@@ -788,12 +788,7 @@ static bool note_name_equal(DumpState *s,
     get_note_sizes(s, note, &head_size, &name_size, NULL);
     head_size = ROUND_UP(head_size, 4);
 
-    if (name_size != len ||
-        memcmp(note + head_size, "VMCOREINFO", len)) {
-        return false;
-    }
-
-    return true;
+    return name_size == len && memcmp(note + head_size, name, len) == 0;
 }
 
 /* write common header, sub header and elf note to vmcore */
Signature · 1 line
2.15.1.355.g36791d7216