This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[patch] Fix for crash in NSS when libc built with --enable-static-nss and exe built with -static
- From: ppluzhnikov at google dot com (Paul Pluzhnikov)
- To: libc-alpha at sourceware dot org
- Cc: ppluzhnikov at google dot com
- Date: Sun, 4 Mar 2012 11:29:04 -0800 (PST)
- Subject: [patch] Fix for crash in NSS when libc built with --enable-static-nss and exe built with -static
- Authentication-results: mr.google.com; spf=pass (google.com: domain of ppluzhnikov@google.com designates 10.14.127.10 as permitted sender) smtp.mail=ppluzhnikov@google.com; dkim=pass header.i=ppluzhnikov@google.com
Greetings,
With the patch from
http://cygwin.com/ml/libc-alpha/2012-03/msg00022.html
(Ping! Could someone apply it?)
a statically-linked executable using NSS will crash like so:
cat t.c
#include <sys/types.h>
#include <pwd.h>
int main()
{
struct passwd *pw = getpwnam("root");
return 0;
}
gcc -g -L. -static t.c
gdb -q ./a.out
Reading symbols from /usr/local/glibc-git/build-static-nss/a.out...done.
(gdb) r
Program received signal SIGSEGV, Segmentation fault.
0x00000000004108b8 in __nss_lookup_function (ni=0x6e5f50, fct_name=0x4aea9f "getpwnam_r") at nsswitch.c:460
460 size_t namlen = (5 + strlen (ni->library->name) + 1
(gdb) bt
#0 0x00000000004108b8 in __nss_lookup_function (ni=0x6e5f50, fct_name=0x4aea9f "getpwnam_r") at nsswitch.c:460
#1 0x0000000000410aae in __nss_lookup (ni=0x7fffffffd4d8, fct_name=0x4aea9f "getpwnam_r", fct2_name=0x0, fctp=0x7fffffffd4d0) at nsswitch.c:161
#2 0x000000000040e446 in __getpwnam_r (name=0x4ab944 "root", resbuf=0x6e0ce0, buffer=0x6e5840 "", buflen=1024, result=0x7fffffffd528) at ../nss/getXXbyYY_r.c:202
#3 0x000000000040e15c in getpwnam (name=0x4ab944 "root") at ../nss/getXXbyYY.c:116
#4 0x0000000000400e86 in main () at t.c:6
(gdb) p *ni
$1 = {next = 0x6e5f90, actions = {NSS_ACTION_CONTINUE, NSS_ACTION_CONTINUE,
NSS_ACTION_CONTINUE, NSS_ACTION_RETURN, NSS_ACTION_RETURN},
library = 0x0, known = 0x6e5c50, name = 0x6e5f80 "files"}
^^^^^^^^^^^^^
Attached patch fixes that.
Thanks,
--
Paul Pluzhnikov
2012-03-04 Paul Pluzhnikov <ppluzhnikov@google.com>
* nss/nsswitch.c (__nss_lookup_function): Fix crash when configured
with --enable-static-nss and using statically linked executable.
diff --git a/nss/nsswitch.c b/nss/nsswitch.c
index 7acb140..d404a4e 100644
--- a/nss/nsswitch.c
+++ b/nss/nsswitch.c
@@ -457,14 +457,11 @@ __nss_lookup_function (service_user *ni, const char *fct_name)
# include "function.def"
{ NULL, NULL }
};
- size_t namlen = (5 + strlen (ni->library->name) + 1
- + strlen (fct_name) + 1);
+ size_t namlen = (5 + strlen (ni->name) + 1 + strlen (fct_name) + 1);
char name[namlen];
/* Construct the function name. */
- __stpcpy (__stpcpy (__stpcpy (name, ni->library->name),
- "_"),
- fct_name);
+ __stpcpy (__stpcpy (__stpcpy (name, ni->name), "_"), fct_name);
result = NULL;
for (tp = &tbl[0]; tp->fname; tp++)