This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libc/12491] New: Calling getpwuid in a statically linked program should return an error, not a seg fault.


http://sourceware.org/bugzilla/show_bug.cgi?id=12491

           Summary: Calling getpwuid in a statically linked program should
                    return an error, not a seg fault.
           Product: glibc
           Version: 2.9
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
        AssignedTo: drepper.fsp@gmail.com
        ReportedBy: geir@cray.com


For a system that is NOT running the nscd daemon, a statically linked program
that calls getpwuid will return a segmentation fault.  The resulting core file
does not provide much help in debugging the problem.   getpwuid or the routines
that it calls should be more robust and not seg fault in this situation, but
rather return an error to the user.

I realize that a link time warning message is shown about using getpwuid in a
statically linked program, but this warning message can easily be overlooked
when building a large application that has other warning messages.

test case:

$ cat getpwuid.c
#include <sys/types.h>
#include <stdio.h>
#include <pwd.h>
int main(){
    int uid;
    struct passwd *pw;

    uid=getuid();
    printf("UID=%d\n", uid);
    pw = getpwuid(uid);
    printf("Done.\n");
    printf("Name=%s\n", pw->pw_name);
    return 0;
}
$  strings /usr/lib64/libc.a | grep -i "release version"
GNU C Library stable release version 2.9 (20081117), by Roland McGrath et al.
$ gcc -g -static -o getpwuid getpwuid.c
/tmp/pbs.581087.sdb/ccyZpaUZ.o: In function `main':
/home/users/geir/getpwuid.c:10: warning: Using 'getpwuid' in statically linked
applications requires at runtime the shared libraries from the glibc version
used for linking
$ ps -ale | grep nscd
$ ./getpwuid
UID=10682
Segmentation fault
$

Here is the unhelpful traceback of the corefile:

(gdb) bt
#0  0x0000000000000000 in ?? ()
#1  0x00002aaaad4fd5dc in __pthread_initialize_minimal_internal ()
   from /lib64/libpthread.so.0
#2  0x00002aaaad4fce49 in _init () from /lib64/libpthread.so.0
#3  0x0000000000000000 in ?? ()
(gdb)

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]