yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-dump-fill-in-the-flat-header-signature-more-pleasing.patch

958e1b
From e40ba375b6007ff227d18aa55be7f1070145ccac Mon Sep 17 00:00:00 2001
958e1b
From: Laszlo Ersek <lersek@redhat.com>
958e1b
Date: Fri, 7 Nov 2014 17:18:07 +0100
958e1b
Subject: [PATCH 20/41] dump: fill in the flat header signature more pleasingly
958e1b
 to the eye
958e1b
958e1b
Message-id: <1415380693-16593-21-git-send-email-lersek@redhat.com>
958e1b
Patchwork-id: 62206
958e1b
O-Subject: [RHEL-7.1 qemu-kvm PATCH 20/26] dump: fill in the flat header signature more pleasingly to the eye
958e1b
Bugzilla: 1157798
958e1b
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
958e1b
RH-Acked-by: Luiz Capitulino <lcapitulino@redhat.com>
958e1b
RH-Acked-by: dgibson <dgibson@redhat.com>
958e1b
958e1b
The "mh.signature" array field has size 16, and is zeroed by the preceding
958e1b
memset(). MAKEDUMPFILE_SIGNATURE expands to a string literal with string
958e1b
length 12 (size 13). There's no need to measure the length of
958e1b
MAKEDUMPFILE_SIGNATURE at runtime, nor for the extra zero-filling of
958e1b
"mh.signature" with strncpy().
958e1b
958e1b
Use memcpy() with MIN(sizeof, sizeof) for robustness (which is an integer
958e1b
constant expression, evaluable at compile time.)
958e1b
958e1b
Approximately-suggested-by: Paolo Bonzini <pbonzini@redhat.com>
958e1b
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
958e1b
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
958e1b
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
958e1b
(cherry picked from commit ae3f88f60fb9f42bb3679311c2fbff8e1868ea47)
958e1b
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
958e1b
---
958e1b
 dump.c | 4 ++--
958e1b
 1 file changed, 2 insertions(+), 2 deletions(-)
958e1b
958e1b
diff --git a/dump.c b/dump.c
958e1b
index 9250594..533b914 100644
958e1b
--- a/dump.c
958e1b
+++ b/dump.c
958e1b
@@ -722,8 +722,8 @@ static int write_start_flat_header(int fd)
958e1b
     int ret = 0;
958e1b
 
958e1b
     memset(&mh, 0, sizeof(mh));
958e1b
-    strncpy(mh.signature, MAKEDUMPFILE_SIGNATURE,
958e1b
-            strlen(MAKEDUMPFILE_SIGNATURE));
958e1b
+    memcpy(mh.signature, MAKEDUMPFILE_SIGNATURE,
958e1b
+           MIN(sizeof mh.signature, sizeof MAKEDUMPFILE_SIGNATURE));
958e1b
 
958e1b
     mh.type = cpu_to_be64(TYPE_FLAT_HEADER);
958e1b
     mh.version = cpu_to_be64(VERSION_FLAT_HEADER);
958e1b
-- 
958e1b
1.8.3.1
958e1b