Patchwork [PATCHv3,09/20] ppc: avoid buffer overrun: use pstrcpy, not strncpy

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

Comments

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

A terminal NUL is required by caller's use of strchr.
It's better not to use strncpy at all, since there is no need
to zero out hundreds of trailing bytes for each iteration.

Signed-off-by: Jim Meyering <meyering@redhat.com>
---
 target-ppc/kvm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Patch

diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c
index a31d278..7f6e4e0 100644
--- a/target-ppc/kvm.c
+++ b/target-ppc/kvm.c
@@ -795,7 +795,7 @@  static int read_cpuinfo(const char *field, char *value, int len)
             break;
         }
         if (!strncmp(line, field, field_len)) {
-            strncpy(value, line, len);
+            pstrcpy(value, len, line);
             ret = 0;
             break;
         }