kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jim Meyering <jim@meyering.net>
To: jim@meyering.net
Cc: Jim Meyering <meyering@redhat.com>,
	Alexander Graf <agraf@suse.de>, Avi Kivity <avi@redhat.com>,
	Marcelo Tosatti <mtosatti@redhat.com>,
	qemu-ppc@nongnu.org (open list:PowerPC),
	kvm@vger.kernel.org (open list:Overall)
Subject: [PATCH 07/22] ppc: avoid buffer overrun: use pstrcpy, not strncpy
Date: Wed,  9 May 2012 11:18:47 +0200	[thread overview]
Message-ID: <1336555142-18302-7-git-send-email-jim@meyering.net> (raw)
In-Reply-To: <1336555142-18302-2-git-send-email-jim@meyering.net>

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(-)

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;
         }
-- 
1.7.10.1.487.ga3935e6


       reply	other threads:[~2012-05-09  9:19 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1336555142-18302-2-git-send-email-jim@meyering.net>
2012-05-09  9:18 ` Jim Meyering [this message]
     [not found] <1336555446-20180-1-git-send-email-jim@meyering.net>
2012-05-09  9:23 ` [PATCH 07/22] ppc: avoid buffer overrun: use pstrcpy, not strncpy Jim Meyering

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1336555142-18302-7-git-send-email-jim@meyering.net \
    --to=jim@meyering.net \
    --cc=agraf@suse.de \
    --cc=avi@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=meyering@redhat.com \
    --cc=mtosatti@redhat.com \
    --cc=qemu-ppc@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).