[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Secure Dereference of NULL-Pointer when using list.h
On 10/4/06, Hendrik Post <hendrik@xxxxxxxxxxxx> wrote:
Hi Ricard,
Thank you for your answer. My problem was my incorrect (?) understanding
of "s->foo". I thought it being equivalent to "(*s).foo" rather than a
direct offset calculation.
They are equivalent. The rule is simple, no value is read unless a
read operation is performed. Also, no value is written unless a write
operation is performed. When you write
a = b;
read operation is required on 'b', and a write on 'a'. But when you say
a; // no operation is specified here
or
; // an empty statement
neither read nor a write is asked to perform by us. The compiler will
thus silently ignore such a statement since we have not asked for any
particular operation over 'a'. A read or write operation has two
steps:
Step 1: Get the address of the variable upon which to operate on
Step 2: Read/Write to that address
Now, when you write
a = &b;
both the above steps are performed over 'a' whereas only step 1 is
performed over 'b'. It's because we've not asked the compiler to do
that. Therefore when you say
a = &(s->foo);
the possible steps are:
Step 1: Get the address of s
Step 2: Read the value(address) contained in s
Step 3: Get the address of member foo inside s
Step 4: Read the value of foo
Step 4 is not performed because we've already obtained our required
result in Step 3 or in other words - we've not asked the compiler to
read the value of foo; only the address of it.
I think I've explained too much,
Best of Luck,
Jinesh.
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/kernelnewbies/
FAQ: http://kernelnewbies.org/faq/