cURL / Mailing Lists / curl-users / Single Mail


[PATCH] Fix segfault in Curl_getaddrinfo().

From: Glen Nakamura <>
Date: Tue, 25 Jun 2002 11:39:08 -1000


I found a bug in Curl_getaddrinfo() while running make check on alpha linux.
The problem is in the following section of code:

  if ( (in=inet_addr(hostname)) != INADDR_NONE ) {
    struct in_addr *addrentry;
    long *buf = (long *)malloc(sizeof(struct hostent)+128);
    ^^^^^^^^^ Why is buf a (long *)? hmm... possibly for alignment?
      return NULL; /* major failure */
    *bufp = (char *)buf;

    h = (struct hostent*)buf;
    h->h_addr_list = (char**)(buf + sizeof(*h));
The offset above is incorrect because buf is a (long *) and the result becomes
"buf + sizeof(*h) * sizeof(long)" which throws off the calculation for the
addr_len parameter passed to MakeIP() and produces the segfault.
Changing buf to a (char *) fixes the calculation but possibly causes
alignment problems on some machines. The attached patch fixes the problem
while avoiding other problems with alignment and -fstrict-aliasing.

- Glen Nakamura

This email is sponsored by: Jabber Inc.
Don't miss the IM event of the season | Special offer for OSDN members!
JabConf 2002, Aug. 20-22, Keystone, CO

Received on 2002-06-25