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

Secure Dereference of NULL-Pointer when using list.h




Hi,


While studying the Infiniband drivers if found an interesting line of code within the preprocessed files from kernel 2.6.14.1:

// 85 "drivers/infiniband/core/mad.c"
entry = (struct ib_mad_port_private *) ((char *)__mptr - (unsigned int) (&((struct ib_mad_port_private *)0) ->port_list) );


This line is the result of a macro expansion from list.h. I wonder why it is safe to dereference the NULL-pointer in the second part of the right side:

(& ((struct ib_mad_port_private *)0) ->port_list) )

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?

Any hints would be appreciated!

Regards,

Hendrik

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