public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libc/12491] New: Calling getpwuid in a statically linked program should return an error, not a seg fault.
@ 2011-02-14 23:32 geir at cray dot com
  2011-03-04 23:55 ` [Bug libc/12491] " geir at cray dot com
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: geir at cray dot com @ 2011-02-14 23:32 UTC (permalink / raw)
  To: glibc-bugs

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.


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-09-12 16:46 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-14 23:32 [Bug libc/12491] New: Calling getpwuid in a statically linked program should return an error, not a seg fault geir at cray dot com
2011-03-04 23:55 ` [Bug libc/12491] " geir at cray dot com
2011-04-18  2:26 ` drepper.fsp at gmail dot com
2011-09-15 16:15 ` geir at cray dot com
2014-06-27 13:51 ` fweimer at redhat dot com
2021-09-12 16:46 ` ovilewade9 at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).