From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44739) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wujs2-0005hx-1v for qemu-devel@nongnu.org; Wed, 11 Jun 2014 10:51:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wujrr-00086R-8g for qemu-devel@nongnu.org; Wed, 11 Jun 2014 10:51:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:3635) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wujrr-00086C-1Y for qemu-devel@nongnu.org; Wed, 11 Jun 2014 10:51:11 -0400 From: Luiz Capitulino Date: Wed, 11 Jun 2014 10:50:46 -0400 Message-Id: <1402498262-20521-2-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1402498262-20521-1-git-send-email-lcapitulino@redhat.com> References: <1402498262-20521-1-git-send-email-lcapitulino@redhat.com> Subject: [Qemu-devel] [PULL 01/17] dump: fill in the flat header signature more pleasingly to the eye List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: peter.maydell@linaro.org Cc: qemu-devel@nongnu.org, anthony@codemonkey.ws From: Laszlo Ersek The "mh.signature" array field has size 16, and is zeroed by the preceding memset(). MAKEDUMPFILE_SIGNATURE expands to a string literal with string length 12 (size 13). There's no need to measure the length of MAKEDUMPFILE_SIGNATURE at runtime, nor for the extra zero-filling of "mh.signature" with strncpy(). Use memcpy() with MIN(sizeof, sizeof) for robustness (which is an integer constant expression, evaluable at compile time.) Approximately-suggested-by: Paolo Bonzini Signed-off-by: Laszlo Ersek Reviewed-by: Paolo Bonzini Signed-off-by: Luiz Capitulino --- dump.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dump.c b/dump.c index e56b7cf..ac4505e 100644 --- a/dump.c +++ b/dump.c @@ -716,8 +716,8 @@ static int write_start_flat_header(int fd) int ret = 0; memset(&mh, 0, sizeof(mh)); - strncpy(mh.signature, MAKEDUMPFILE_SIGNATURE, - strlen(MAKEDUMPFILE_SIGNATURE)); + memcpy(mh.signature, MAKEDUMPFILE_SIGNATURE, + MIN(sizeof mh.signature, sizeof MAKEDUMPFILE_SIGNATURE)); mh.type = cpu_to_be64(TYPE_FLAT_HEADER); mh.version = cpu_to_be64(VERSION_FLAT_HEADER); -- 1.9.3