bug-glibc
[Top][All Lists]
Advanced

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

glibc 2.2.5 gethostbyname -static


From: Mark Allen
Subject: glibc 2.2.5 gethostbyname -static
Date: Tue, 26 Aug 2003 17:54:56 -0700 (PDT)

I've hit this bug on several redhat machines which have rpms
ranging from glibc-2.2.4-13 to glibc-2.2.5-43.

The problem occurs when a statically linked executable calls
both putenv() and gethostbyname().  The gethostbyname segfaults.

    % cc -o x -DHOSTNAME=\"`hostname -s`\" prog.c -static
    % ./x
    > Putting >>A0=B0<< to env
    > Putting >>A1=B1<< to env
    > Segmentation fault (core dumped)

The stack trace doesn't seem particularly enlightening:
> #0  0x4202b250 in ?? ()
> #1  0x4005816f in ?? ()
> #2  0x4004e1a3 in ?? ()
> #3  0x4004f425 in ?? ()
> #4  0x0805001a in gethostbyname_r ()
> #5  0x0804fe67 in gethostbyname ()
> #6  0x08048288 in main ()
> #7  0x0804838e in __libc_start_main ()

I also tried downloading and buliding a new glibc-2.2.5 to test
with but didn't have much luck.  I didn't want to install it,
so after doing "make check" I mimicked the steps used to
compile/run the tststatic test.

But that version failed (hung in gethostbyname) even when I modified
the testcase to not do the putenv, so I figure this is just some
problem with my usage of the 2.2.5 build in my home directory.

So the point is I've only actually tested this on machines with
redhat rpms of glib-2.2.4 and glibc-2.2.5.  Anyway here's the
source:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <netdb.h>
int
main() {
        int i;
        struct hostent *hp;
        char hostname[16];
        char env[256];
        strcpy(hostname, HOSTNAME);
        for (i=0; i<1000; i++) {
                hp = 0;
                sprintf(env, "A%d=B%d", i, i);
                printf("Putting >>%s<< to env\n", env);
                putenv(strdup(env));
                while (!hp) {
                        hp = gethostbyname((const char*)hostname);
                }
        }
        printf("success\n");
        return 0;
}

 - Mark


__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com




reply via email to

[Prev in Thread] Current Thread [Next in Thread]