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

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

 



GCC translates the expression into the offset of the field port_list as
intended, but doing this involves dereferencing a NULL-pointer
(evaluates to 0). The expression can only be correct if one assumes that
the dereference will be optimized away - why is it safe to assume that?
this is similar to the offsetof(...) macro (stddef.h). but basically
it (the offsetof macro at-least) works like this [consider a shorter
sample  "& ((S *0) ->foo) )"]:

1. (( S *)0) :       takes the integer zero and casts it as a pointer to S.
2. ((S *)0)->foo: dereferences that pointer to point to structure member foo.
3. &(((S *)0)->foo):  computes the address of foo

does that make any sense ?

kind regards
anupam
--
In the beginning was the lambda, and the lambda was with Emacs, and
Emacs was the lambda.

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[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