public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jeremy Fitzhardinge <jeremy@goop.org>
To: "René Scharfe" <rene.scharfe@lsrfire.ath.cx>
Cc: Andi Kleen <ak@suse.de>,
	Andrew Morton <akpm@linux-foundation.org>,
	lkml <linux-kernel@vger.kernel.org>,
	Chris Wright <chrisw@sous-sol.org>,
	Randy Dunlap <randy.dunlap@oracle.com>,
	YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>,
	Akinobu Mita <akinobu.mita@gmail.com>,
	Arnaldo Carvalho de Melo <acme@mandriva.com>,
	Al Viro <viro@ftp.linux.org.uk>,
	Panagiotis Issaris <takis@issaris.org>
Subject: Re: [patch 3/7] add kstrndup
Date: Fri, 11 May 2007 14:18:18 -0700	[thread overview]
Message-ID: <4644DD9A.2080001@goop.org> (raw)
In-Reply-To: <4644D779.30908@lsrfire.ath.cx>

René Scharfe wrote:
>> +	len = strlen(s);
>> +	if (len > max)
>> +		len = max;
>>     
>
> You can avoid to run beyond max and save two lines by using strnlen:
>
> 	len = strnlen(s, max);
>   

OK.  Didn't know about strnlen.

Subject: Use strnlen in kstrndup

strnlen prevents over-reading the input.

Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Cc: René Scharfe <rene.scharfe@lsrfire.ath.cx>

---
 mm/util.c |    4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

===================================================================
--- a/mm/util.c
+++ b/mm/util.c
@@ -53,9 +53,7 @@ char *kstrndup(const char *s, size_t max
 	if (!s)
 		return NULL;
 
-	len = strlen(s);
-	if (len > max)
-		len = max;
+	len = strnlen(s, max);
 	buf = kmalloc_track_caller(len+1, gfp);
  	if (buf) {
 		memcpy(buf, s, len);



  reply	other threads:[~2007-05-11 21:18 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-05-10 23:57 [patch 0/7] A series of cleanup patches Jeremy Fitzhardinge
2007-05-10 23:57 ` [patch 1/7] i386: move common parts of smp into their own file Jeremy Fitzhardinge
2007-05-10 23:57 ` [patch 2/7] use elfnote.h to generate vsyscall notes Jeremy Fitzhardinge
2007-05-11 19:47   ` Roland McGrath
2007-05-11 19:48     ` Jeremy Fitzhardinge
2007-05-11 20:06     ` Jeremy Fitzhardinge
2007-05-10 23:57 ` [patch 3/7] add kstrndup Jeremy Fitzhardinge
2007-05-11 20:52   ` René Scharfe
2007-05-11 21:18     ` Jeremy Fitzhardinge [this message]
2007-05-10 23:57 ` [patch 4/7] add argv_split() Jeremy Fitzhardinge
2007-05-11 22:57   ` Randy Dunlap
2007-05-10 23:57 ` [patch 5/7] split usermodehelper setup from execution Jeremy Fitzhardinge
2007-05-10 23:57 ` [patch 6/7] Add common orderly_poweroff() Jeremy Fitzhardinge
2007-05-11 22:56   ` Randy Dunlap
2007-07-16 19:52   ` Andrew Morton
2007-07-16 19:59     ` Jeremy Fitzhardinge
2007-07-16 21:31     ` David Miller
2007-07-16 21:42       ` Andrew Morton
2007-05-10 23:57 ` [patch 7/7] tidy up usermode helper waiting a bit Jeremy Fitzhardinge
2007-05-11 19:45   ` Johannes Berg
2007-05-11 20:01     ` Jeremy Fitzhardinge

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=4644DD9A.2080001@goop.org \
    --to=jeremy@goop.org \
    --cc=acme@mandriva.com \
    --cc=ak@suse.de \
    --cc=akinobu.mita@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=chrisw@sous-sol.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=randy.dunlap@oracle.com \
    --cc=rene.scharfe@lsrfire.ath.cx \
    --cc=takis@issaris.org \
    --cc=viro@ftp.linux.org.uk \
    --cc=yoshfuji@linux-ipv6.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