[Qemu-devel] [PATCH] dump: fix note_name_equal()

Marc-André Lureau posted 1 patch 6 years, 4 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20171212150909.1831-1-marcandre.lureau@redhat.com
Test checkpatch passed
Test docker passed
Test ppc passed
Test s390x passed
dump.c | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)
[Qemu-devel] [PATCH] dump: fix note_name_equal()
Posted by Marc-André Lureau 6 years, 4 months ago
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.

Suggested-by: Andrew Jones <drjones@redhat.com>
Reported-by: Laszlo Ersek <lersek@redhat.com>
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 dump.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/dump.c b/dump.c
index d4a8c942eb..e9dfed060a 100644
--- a/dump.c
+++ b/dump.c
@@ -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 */
-- 
2.15.1.355.g36791d7216


Re: [Qemu-devel] [PATCH] dump: fix note_name_equal()
Posted by Laszlo Ersek 6 years, 4 months ago
On 12/12/17 16:09, Marc-André Lureau wrote:
> 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.
> 
> Suggested-by: Andrew Jones <drjones@redhat.com>
> Reported-by: Laszlo Ersek <lersek@redhat.com>
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  dump.c | 7 +------
>  1 file changed, 1 insertion(+), 6 deletions(-)
> 
> diff --git a/dump.c b/dump.c
> index d4a8c942eb..e9dfed060a 100644
> --- a/dump.c
> +++ b/dump.c
> @@ -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 */
> 

Reviewed-by: Laszlo Ersek <lersek@redhat.com>

Re: [Qemu-devel] [PATCH] dump: fix note_name_equal()
Posted by Andrew Jones 6 years, 4 months ago
On Tue, Dec 12, 2017 at 04:09:09PM +0100, Marc-André Lureau wrote:
> 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.
> 
> Suggested-by: Andrew Jones <drjones@redhat.com>
> Reported-by: Laszlo Ersek <lersek@redhat.com>
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  dump.c | 7 +------
>  1 file changed, 1 insertion(+), 6 deletions(-)
> 
> diff --git a/dump.c b/dump.c
> index d4a8c942eb..e9dfed060a 100644
> --- a/dump.c
> +++ b/dump.c
> @@ -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 */
> -- 
> 2.15.1.355.g36791d7216
>

Reviewed-by: Andrew Jones <drjones@redhat.com>