Patchwork [PATCHv2,09/22] ppc: avoid buffer overrun: use pstrcpy, not strncpy

login
register
mail settings
Submitter Jim Meyering
Date May 30, 2012, 7:46 a.m.
Message ID <1338364001-13892-10-git-send-email-jim@meyering.net>
Download mbox | patch
Permalink /patch/161887/
State New
Headers show

Comments

Jim Meyering - May 30, 2012, 7:46 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 c09cc39..fb79e9f 100644
--- a/target-ppc/kvm.c
+++ b/target-ppc/kvm.c
@@ -587,7 +587,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;
         }