Skip to contentSkip to conversation

Fix buffer overflow when writing dh->signature

PATCH In review Bernhard Walle 2 participants 2 messages Feb 21, 2010 – Feb 22, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix buffer overflow when writing dh->signature

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.

---
 makedumpfile.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
makedumpfile.c +1 -1
index 4fa6f50..855c718 100644
@@ -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;
Signature · 7 lines
1.6.4.2


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
#1 lore raw

Hi Bernhard,

Thank you for your patch.
The patch is good for me, and it has been merged into the git tree.

http://makedumpfile.git.sourceforge.net/git/gitweb.cgi?p=makedumpfile/makedumpfile;a=summary

Thanks
Ken'ichi Ohmichi

Quoted 21 lines · Bernhard Walle

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.

---
 makedumpfile.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
makedumpfile.c +0 -0
index 4fa6f50..855c718 100644

makedumpfile.c write_kdump_header(void) · line 5460

Quoted 8 lines
makedumpfile.c +1 -1
@@ -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;

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec