summaryrefslogtreecommitdiffstats
path: root/src/lib/krb5/os/dnsglue.c
diff options
context:
space:
mode:
authorTom Yu <tlyu@mit.edu>2005-09-08 23:13:39 +0000
committerTom Yu <tlyu@mit.edu>2005-09-08 23:13:39 +0000
commita9c2b6881159fc80f3bcf1f71684712a9e236dcd (patch)
tree5040caed5335366883a603a9ef2124c39d6344e9 /src/lib/krb5/os/dnsglue.c
parent0333abc05fd1580ea00d7610d81f37435956b629 (diff)
downloadkrb5-a9c2b6881159fc80f3bcf1f71684712a9e236dcd.tar.gz
krb5-a9c2b6881159fc80f3bcf1f71684712a9e236dcd.tar.xz
krb5-a9c2b6881159fc80f3bcf1f71684712a9e236dcd.zip
Rework logic for using res_ninit() and friends to fall back to
res_init() if res_ndestroy() isn't available. ticket: 3172 tags: pullup git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@17377 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/lib/krb5/os/dnsglue.c')
-rw-r--r--src/lib/krb5/os/dnsglue.c30
1 files changed, 20 insertions, 10 deletions
diff --git a/src/lib/krb5/os/dnsglue.c b/src/lib/krb5/os/dnsglue.c
index 5d2db36952..03419bf779 100644
--- a/src/lib/krb5/os/dnsglue.c
+++ b/src/lib/krb5/os/dnsglue.c
@@ -29,6 +29,18 @@
#include "dnsglue.h"
/*
+ * Only use res_ninit() if there's also a res_ndestroy(), to avoid
+ * memory leaks (Linux & Solaris) and outright corruption (AIX 4.x,
+ * 5.x). While we're at it, make sure res_nsearch() is there too.
+ *
+ * In any case, it is probable that platforms having broken
+ * res_ninit() will have thread safety hacks for res_init() and _res.
+ */
+#if HAVE_RES_NINIT && HAVE_RES_NDESTROY && HAVE_RES_NSEARCH
+#define USE_RES_NINIT
+#endif
+
+/*
* Opaque handle
*/
struct krb5int_dns_state {
@@ -53,7 +65,7 @@ static int initparse(struct krb5int_dns_state *);
/*
* krb5int_dns_init()
*
- * Initialize an opaue handl. Do name lookup and initial parsing of
+ * Initialize an opaque handle. Do name lookup and initial parsing of
* reply, skipping question section. Prepare to iterate over answer
* section. Returns -1 on error, 0 on success.
*/
@@ -61,7 +73,7 @@ int
krb5int_dns_init(struct krb5int_dns_state **dsp,
char *host, int nclass, int ntype)
{
-#if HAVE_RES_NSEARCH
+#if USE_RES_NINIT
struct __res_state statbuf;
#endif
struct krb5int_dns_state *ds;
@@ -86,11 +98,13 @@ krb5int_dns_init(struct krb5int_dns_state **dsp,
ds->cur_ans = 0;
#endif
-#if HAVE_RES_NSEARCH
+#if USE_RES_NINIT
ret = res_ninit(&statbuf);
+#else
+ ret = res_init();
+#endif
if (ret < 0)
return -1;
-#endif
do {
p = (ds->ansp == NULL)
@@ -103,7 +117,7 @@ krb5int_dns_init(struct krb5int_dns_state **dsp,
ds->ansp = p;
ds->ansmax = nextincr;
-#if HAVE_RES_NSEARCH
+#if USE_RES_NINIT
len = res_nsearch(&statbuf, host, ds->nclass, ds->ntype,
ds->ansp, ds->ansmax);
#else
@@ -134,12 +148,8 @@ krb5int_dns_init(struct krb5int_dns_state **dsp,
ret = 0;
errout:
-#if HAVE_RES_NSEARCH
-#if HAVE_RES_NDESTROY
+#if USE_RES_NINIT
res_ndestroy(&statbuf);
-#else
- res_nclose(&statbuf);
-#endif
#endif
if (ret < 0) {
if (ds->ansp != NULL) {