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

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