[15377] in bugtraq
Re: local root on linux 2.2.15
daemon@ATHENA.MIT.EDU (Ben Pfaff)
Fri Jun 16 15:00:16 2000
Message-Id: <87vgzas5vl.fsf@pfaffben.user.msu.edu>
Date: Thu, 15 Jun 2000 22:43:10 -0400
Reply-To: pfaffben@msu.edu
From: Ben Pfaff <pfaffben@MSU.EDU>
To: BUGTRAQ@SECURITYFOCUS.COM
In-Reply-To: Peter da Silva's message of "Thu, 15 Jun 2000 10:44:07 -0500"
Peter da Silva <peter@SCARYDEVIL.ORG> writes:
> In article <87bt184i7z.fsf@arabella.intern.opera.no> you write:
> > cap_user_header_t header;
> > cap_user_data_t data;
[...]
> header = malloc(sizeof (cap_user_header_t) );
> data = malloc(sizeof (cap_user_data_t) );
The comp.lang.c approved version of these statements would read:
header = malloc (sizeof *header);
data = malloc (sizeof *data);
given that the declarations were actually
cap_user_header_t *header;
cap_user_data_t *data;
or that cap_user_header_t and cap_user_data_t were typedefs of
pointer types.
There's a couple of reasons to do it this way:
* If you ever change the type that `header' or `data'
points to, for whatever reason, it's not necessary to
change the malloc() call as well. This is convenient
and a handy safeguard against forgetting to change all
your malloc() calls.
* Taking the size of an object makes your sizeof call more
similar to your declaration, which makes writing the
statement less error-prone.
However, if the declarations were as above, with Peter's
statements, there is something wrong. It is almost certainly a
mistake to use the same type for both the pointer and the
pointed-to object, as Peter's suggested code implies; the actual
equivalent of his code using sizeof on an object would be this:
header = malloc (sizeof header);
data = malloc (sizeof data);
Though I do not know what a cap_user_header_t or a
cap_user_data_t is, I can hardly believe that this is correct.
--
"Welcome to the Slippery Slope. Here is your handbasket.
Say, can you work 70 hours this week?"
--Ron Mansolino