Comment 10 for bug 589855

Revision history for this message
Kees Cook (kees) wrote : Re: incorrect stack size calculation when building with -O0

The problem is the netdb.h include file. This crashes:

#include <netdb.h>
#include <netinet/in.h>
void resolv(void) {
 struct in_addr h_addr;
 *(unsigned int*)&h_addr = 0;
}
int main(int argc, char *argv[] ) {
 resolv();
 return 0;
}

If netdb.h is removed, it's fine. This appears to be because the "h_addr" macro is retained, and rewrites the main body of the code:

- struct in_addr h_addr;
+ struct in_addr h_addr_list[0];
- *(unsigned int*)&h_addr = 0;
+ *(unsigned int*)&h_addr_list[0] = 0;

It seems that "h_addr" is a reserved name if netdb.h is included to support the old-style naming. From "man gethostbyname":

       The hostent structure is defined in <netdb.h> as follows:

           struct hostent {
               char *h_name; /* official name of host */
               char **h_aliases; /* alias list */
               int h_addrtype; /* host address type */
               int h_length; /* length of address */
               char **h_addr_list; /* list of addresses */
           }
           #define h_addr h_addr_list[0] /* for backward compatibility */

Is this a bug in glibc, then, or user error?