public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Thomas Jarosch <thomas.jarosch@intra2net.com>
To: Christoph Lameter <cl@gentwo.org>
Cc: linux-kernel@vger.kernel.org, Pekka Enberg <penberg@cs.helsinki.fi>
Subject: Re: [slabinfo PATCH] Fix off-by-one after readlink() call
Date: Fri, 14 Oct 2011 19:26:00 +0200	[thread overview]
Message-ID: <4E9870A8.2010905@intra2net.com> (raw)
In-Reply-To: <alpine.DEB.2.00.1110141214270.6411@router.home>

On 10/14/2011 07:16 PM, Christoph Lameter wrote:
>> index 868cc93..cc1a378 100644
>> --- a/tools/slub/slabinfo.c
>> +++ b/tools/slub/slabinfo.c
>> @@ -1145,7 +1145,7 @@ static void read_slab_dir(void)
>>  		switch (de->d_type) {
>>  		   case DT_LNK:
>>  			alias->name = strdup(de->d_name);
>> -			count = readlink(de->d_name, buffer, sizeof(buffer));
>> +			count = readlink(de->d_name, buffer, sizeof(buffer)-1);
>>
> 
> DESCRIPTION
>        readlink()  places  the  contents  of the symbolic link path in the buffer buf, which has size bufsiz.  readlink() does not append a
>        null byte to buf.  It will truncate the contents (to a length of bufsiz characters), in case the buffer is too small to hold all  of
>        the contents.

The problem is the line after the readlink() call:

buffer[count] = '\0';

The common technique is to reduce the buffer size by one.
Another fix would be to check

"
if (count < 0 || count == sizeof(buffer))
    fatal();
"

Reducing the buffer size by one is easier IMHO.

Cheers,
Thomas

  reply	other threads:[~2011-10-14 17:26 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-14 16:56 [slabinfo PATCH] Fix off-by-one after readlink() call Thomas Jarosch
2011-10-14 17:16 ` Christoph Lameter
2011-10-14 17:26   ` Thomas Jarosch [this message]
2011-10-14 17:57     ` Christoph Lameter
2011-10-14 19:53     ` David Rientjes
2011-10-17  7:16       ` Pekka Enberg
2011-10-17 14:48         ` [slabinfo PATCH v2] Fix off-by-one buffer corruption " Thomas Jarosch

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=4E9870A8.2010905@intra2net.com \
    --to=thomas.jarosch@intra2net.com \
    --cc=cl@gentwo.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=penberg@cs.helsinki.fi \
    /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