From: Takashi Iwai <tiwai@suse.de>
To: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Willy Tarreau <willy@w.ods.org>, XIAO Gang <xiao@unice.fr>,
Linux Kernel Development <linux-kernel@vger.kernel.org>
Subject: Re: Suggestion on "int len" sanity
Date: Fri, 03 Jun 2005 14:47:00 +0200 [thread overview]
Message-ID: <s5hfyvzr4jf.wl@alsa2.suse.de> (raw)
In-Reply-To: <Pine.LNX.4.62.0506031142050.16362@numbat.sonytel.be>
At Fri, 3 Jun 2005 11:42:23 +0200 (CEST),
Geert Uytterhoeven wrote:
>
> On Wed, 1 Jun 2005, Willy Tarreau wrote:
> > On Wed, Jun 01, 2005 at 09:06:33AM +0200, XIAO Gang wrote:
> > > I would like to make a security suggestion.
> > >
> > > There are many length variables in the kernel, locally declared as "len"
> > > or "length", either as "int", "unsigned int" or "size_t". However,
> > > declaring a length as "int" leads easily to an erroneous situation, as
> > > the author (or even a code checker) might make the implicite hypothesis
> > > that the length is positive, so that it is enough to make a sanity check
> > > of the kind
> > >
> > > if (length > limit) ERROR;
> > >
> > > which is not enough.
> > >
> > > On the other hand, when a variable is named "len" or "length", it is
> > > usually used for length and never should go negative. So could I suggest
> > > that the declarations of these variables to be uniformized to "size_t",
> > > via a gradual but sysmatic cleanup?
> >
> > Probably true for most cases, but be careful of code which would use
> > -1 to report some errors if such thing exists.
>
> In that case, use ssize_t.
In some cases, we may want to avoid [s]size_t because it varies on 32
and 64bit archs (e.g. ioctl parameters)...
Takashi
next prev parent reply other threads:[~2005-06-03 12:47 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-06-01 7:06 Suggestion on "int len" sanity XIAO Gang
2005-06-01 13:46 ` Jörn Engel
2005-06-01 20:39 ` Willy Tarreau
2005-06-03 9:42 ` Geert Uytterhoeven
2005-06-03 12:47 ` Takashi Iwai [this message]
-- strict thread matches above, loose matches on Subject: below --
2005-06-02 7:28 XIAO Gang
2005-06-02 8:48 ` Jörn Engel
2005-06-02 9:12 ` XIAO Gang
2005-06-02 9:47 ` Jörn Engel
2005-06-03 9:45 ` Geert Uytterhoeven
2005-06-03 12:20 ` Al Viro
2005-06-03 14:19 ` Jörn Engel
2005-06-03 12:28 ` Andreas Schwab
2005-06-03 12:43 ` Geert Uytterhoeven
2005-06-03 14:38 ` Andreas Schwab
2005-06-03 18:04 ` randy_dunlap
2005-06-03 18:09 ` Lars Marowsky-Bree
2005-06-03 18:16 ` randy_dunlap
2005-06-04 11:28 ` Christoph Hellwig
2005-06-04 16:58 ` randy_dunlap
2005-06-04 17:07 ` Jörn Engel
2005-06-04 17:11 ` randy_dunlap
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=s5hfyvzr4jf.wl@alsa2.suse.de \
--to=tiwai@suse.de \
--cc=geert@linux-m68k.org \
--cc=linux-kernel@vger.kernel.org \
--cc=willy@w.ods.org \
--cc=xiao@unice.fr \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.