[tor-bugs] #3596 [Pluggable transport]: obfsproxy: don't reinvent offsetof
Tor Bug Tracker & Wiki
torproject-admin at torproject.org
Thu Jul 14 20:35:32 UTC 2011
#3596: obfsproxy: don't reinvent offsetof
---------------------------------+------------------------------------------
Reporter: zwol | Owner: asn
Type: defect | Status: new
Priority: normal | Milestone:
Component: Pluggable transport | Version:
Keywords: | Parent:
Points: | Actualpoints:
---------------------------------+------------------------------------------
Change 9d96eb94 introduced a bogon to util.h:
`#define OFFSETOF(container_type, element) \
(((char*)&((container_type*)0)->element) - ((char*)
((container_type*)0)))
`
It is not necessary to reinvent this particular wheel -- `stddef.h`, which
is part of C89 and is well-supported everywhere, provides `offsetof` --
and it's actually wrong: there is a dereference of the null pointer here,
and that causes undefined behavior, even when it's inside the operand of
`&`. (I am not aware of any compiler that presently generates "incorrect"
results for this construct, but it did cause the compiler itself to crash
in some (probably never-released) versions of GCC:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17396 .)
Please apply attached patch. I also renamed UPCAST to DOWNCAST,
consistent with C++ terminology (the type is becoming more specific,
that's downward).
--
Ticket URL: <https://trac.torproject.org/projects/tor/ticket/3596>
Tor Bug Tracker & Wiki <https://trac.torproject.org/>
The Tor Project: anonymity online
More information about the tor-bugs
mailing list