httpd-apreq-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bojan Smojver <>
Subject Bug in apreq_attr_to_type macro
Date Thu, 18 Sep 2003 01:05:14 GMT
The following macro produces unwanted results if P == NULL.

#define apreq_attr_to_type(T,A,P) ( (T*) ((char*)(P)-offsetof(T,A)) )

Basically, you get back a non-NULL value, thus believing that this is an actual
valid memory address. Two problems with that: you can't tell that you actually
found nothing and the code segfaults. Something like this would be a bit better

#define apreq_attr_to_type(T,A,P) \
        ( (P) ? ((T*) ((char*)(P)-offsetof(T,A))) : NULL )

I've tested this in my code and it seems to work, at least for apreq_cookie()
call, which relies on the above macro (through apreq_value_to_cookie macro) to
fetch cookies from the table. I've tested this with Apache 2.0.47 on Red Hat 9.


View raw message