Re: Secure Dereference of NULL-Pointer when using list.h

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On Thu, 5 Oct 2006, Jinesh K J wrote:

In this case we only need to write this as:

*( (volatile char *) 0);

But unlike the value, the address is not volatile. It's not a variable.

I'm not sure I agree. A 'volatile char *' means 'a pointer to something that is volatile'. However ...

&(*( (volatile char *) 0));

will still have no side effect. Only the char is volatile, not the address, right? So,

... in this case you are not referencing location zero, mainly (re-)computing its address. What 'volatile' says, at least to my understanding, is that the compiler may not optimize away an access to the variable (memory location) in question. If however other rules of C do not raise the need for accessing the location in the first place, there will be no access, regardless of the 'volatile' qualifier.

I would say, in this case, that the memory location is considered volatile, but the rules of C (taking the address) mean that there is no access to it, even though initially it may look that way.

s->foo;  // fetches the value of foo(ideally)

&(s->foo); // will not fetch the value of foo - only compute its address - since, computing the address of foo (here, by reading the variable s) has no operation over the value of foo. So, this expression must have side effect only upon 's', if there ever is any.

Agreed.

...
So I believe that in a recommended implementation,

a;

must fetch the value of 'a', though it should be discarded. But then
the compiler in our case optimises it (by not reading 'a'), unless 'a'
is declared as 'volatile'.

That's my interpretation tool.

/Ricard
--
Ricard Wolf Wanderlöf                           ricardw(at)axis.com
Axis Communications AB, Lund, Sweden            www.axis.com
Phone +46 46 272 2016                           Fax +46 46 13 61 30

[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux