getpwuid_r causes core dumps
"Peter C. Norton" <[email protected]>
| Newsgroups | gmane.comp.db.tds.freetds |
|---|---|
| Message-ID | <[email protected]> |
In a recent test our users saw that freetds was core dumping in threadsafe.c. The following is the issue:
diff -u -r1.1.1.5 -r1.2
--- threadsafe.c 17 Sep 2010 17:11:06 -0000 1.1.1.5
+++ threadsafe.c 15 Nov 2010 22:37:41 -0000 1.2
@@ -516,12 +516,14 @@
#ifndef _WIN32
/* if is available getpwuid_r use it */
#if defined(HAVE_GETUID) && defined(HAVE_GETPWUID_R)
- struct passwd *pw, bpw;
+ struct passwd *pw = NULL, bpw;
char buf[1024];
# if defined(HAVE_FUNC_GETPWUID_R_5)
if (getpwuid_r(getuid(), &bpw, buf, sizeof(buf), &pw))
return NULL;
+ if (pw == NULL)
+ return NULL;
# elif defined(HAVE_FUNC_GETPWUID_R_4_PW)
if (!(pw = getpwuid_r(getuid(), &bpw, buf, sizeof(buf))))
getpwuid_r can return 0 when a lookup hasn't found a matching entry.
This seems to work for us, but it may be more correct to check errno.
-Peter