Patchwork [PATCHv3,07/20] lm32: avoid buffer overrun

login
register
mail settings
Submitter Jim Meyering
Date Oct. 4, 2012, 11:09 a.m.
Message ID <1349349003-15672-8-git-send-email-jim@meyering.net>
Download mbox | patch
Permalink /patch/189258/
State New
Headers show

Comments

Jim Meyering - Oct. 4, 2012, 11:09 a.m.
From: Jim Meyering <meyering@redhat.com>

Actually do what the comment says, using pstrcpy NUL-terminate:
strncpy does not always do that.

Signed-off-by: Jim Meyering <meyering@redhat.com>
---
 hw/lm32_hwsetup.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Patch

diff --git a/hw/lm32_hwsetup.h b/hw/lm32_hwsetup.h
index 8fc285e..70dc61f 100644
--- a/hw/lm32_hwsetup.h
+++ b/hw/lm32_hwsetup.h
@@ -96,7 +96,7 @@  static inline void hwsetup_add_tag(HWSetup *hw, enum hwsetup_tag t)

 static inline void hwsetup_add_str(HWSetup *hw, const char *str)
 {
-    strncpy(hw->ptr, str, 31); /* make sure last byte is zero */
+    pstrcpy(hw->ptr, 32, str);
     hw->ptr += 32;
 }