[PATCH] Fix buffer overflow when writing dh->signature

Bernhard Walle bernhard at bwalle.de
Sun Feb 21 05:12:58 EST 2010


Fix following compile warning when building with gcc 4.5 and with the
flags '-O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables
-fasynchronous-unwind-tables -g -O2 -Wall'.

  In function 'strcpy',
      inlined from 'write_kdump_header' at makedumpfile.c:5457:8: \
      /usr/include/bits/string3.h:107:3: warning: call to \
      __builtin___strcpy_chk will always overflow destination buffer

Solution: Don't copy the terminating zero byte.

Signed-off-by: Bernhard Walle <bernhard at bwalle.de>
---
 makedumpfile.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/makedumpfile.c b/makedumpfile.c
index 4fa6f50..855c718 100644
--- a/makedumpfile.c
+++ b/makedumpfile.c
@@ -5454,7 +5454,7 @@ write_kdump_header(void)
 	/*
 	 * Write common header
 	 */
-	strcpy(dh->signature, KDUMP_SIGNATURE);
+	strncpy(dh->signature, KDUMP_SIGNATURE, strlen(KDUMP_SIGNATURE));
 	dh->header_version = 3;
   	dh->block_size     = info->page_size;
 	dh->sub_hdr_size   = sizeof(kh) + info->size_vmcoreinfo;
-- 
1.6.4.2




More information about the kexec mailing list