summaryrefslogtreecommitdiff
path: root/usr/src/lib/libresolv2
diff options
context:
space:
mode:
authorjs198686 <none@none>2007-03-15 08:58:45 -0700
committerjs198686 <none@none>2007-03-15 08:58:45 -0700
commit168c213023b7f347f11abfc72f448b0c621ab718 (patch)
treeaa57c8e9bd8448a3084e5588e7e0391fe01c087d /usr/src/lib/libresolv2
parent4e54023805e14cf984b9f0041df73c16334a7a88 (diff)
downloadillumos-joyent-168c213023b7f347f11abfc72f448b0c621ab718.tar.gz
6300853 libresolv net_data_init should not increment once until it is done initializing
6527020 libresolv does not handle mutexes correctly
Diffstat (limited to 'usr/src/lib/libresolv2')
-rw-r--r--usr/src/lib/libresolv2/common/irs/gai_strerror.c39
-rw-r--r--usr/src/lib/libresolv2/common/irs/irs_data.c22
2 files changed, 43 insertions, 18 deletions
diff --git a/usr/src/lib/libresolv2/common/irs/gai_strerror.c b/usr/src/lib/libresolv2/common/irs/gai_strerror.c
index 652d51debd..e9e1131729 100644
--- a/usr/src/lib/libresolv2/common/irs/gai_strerror.c
+++ b/usr/src/lib/libresolv2/common/irs/gai_strerror.c
@@ -1,5 +1,5 @@
/*
- * Copyright 1999-2002 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -69,20 +69,30 @@ gai_strerror(int ecode) {
return (gai_errlist[ecode]);
#ifdef DO_PTHREADS
- if (!once) {
- pthread_mutex_lock(&lock);
- if (!once++)
- pthread_key_create(&key, free);
- pthread_mutex_unlock(&lock);
- }
+ if (!once) {
+ if (pthread_mutex_lock(&lock) != 0)
+ goto unknown;
+ if (!once) {
+ if (pthread_key_create(&key, free) != 0) {
+ pthread_mutex_unlock(&lock);
+ goto unknown;
+ }
+ once = 1;
+ }
+ if (pthread_mutex_unlock(&lock) != 0)
+ goto unknown;
+ }
buf = pthread_getspecific(key);
- if (buf == NULL) {
+ if (buf == NULL) {
buf = malloc(EAI_BUFSIZE);
- if (buf == NULL)
- return ("unknown error");
- pthread_setspecific(key, buf);
- }
+ if (buf == NULL)
+ goto unknown;
+ if (pthread_setspecific(key, buf) != 0) {
+ free(buf);
+ goto unknown;
+ }
+ }
#endif
/*
* XXX This really should be snprintf(buf, EAI_BUFSIZE, ...).
@@ -90,4 +100,9 @@ gai_strerror(int ecode) {
*/
sprintf(buf, "%s: %d", gai_errlist[gai_nerr - 1], ecode);
return (buf);
+
+#ifdef DO_PTHREADS
+unknown:
+ return ("unknown error");
+#endif
}
diff --git a/usr/src/lib/libresolv2/common/irs/irs_data.c b/usr/src/lib/libresolv2/common/irs/irs_data.c
index 14d965bf0c..5db332a87f 100644
--- a/usr/src/lib/libresolv2/common/irs/irs_data.c
+++ b/usr/src/lib/libresolv2/common/irs/irs_data.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -130,10 +130,17 @@ net_data_init(const char *conf_file) {
struct net_data *net_data;
if (!once) {
- pthread_mutex_lock(&keylock);
- if (!once++)
- pthread_key_create(&key, net_data_destroy);
- pthread_mutex_unlock(&keylock);
+ if (pthread_mutex_lock(&keylock) != 0)
+ return (NULL);
+ if (!once) {
+ if (pthread_key_create(&key, net_data_destroy) != 0) {
+ pthread_mutex_unlock(&keylock);
+ return (NULL);
+ }
+ once = 1;
+ }
+ if (pthread_mutex_unlock(&keylock) != 0)
+ return (NULL);
}
net_data = pthread_getspecific(key);
#endif
@@ -143,7 +150,10 @@ net_data_init(const char *conf_file) {
if (net_data == NULL)
return (NULL);
#ifdef DO_PTHREADS
- pthread_setspecific(key, net_data);
+ if (pthread_setspecific(key, net_data) != 0) {
+ net_data_destroy(net_data);
+ return (NULL);
+ }
#endif
}