]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
2009. [bug] libbind: coverity fixes. [RT #15808]
authorMark Andrews <marka@isc.org>
Fri, 10 Mar 2006 00:17:21 +0000 (00:17 +0000)
committerMark Andrews <marka@isc.org>
Fri, 10 Mar 2006 00:17:21 +0000 (00:17 +0000)
23 files changed:
CHANGES
lib/bind/dst/dst_api.c
lib/bind/dst/hmac_link.c
lib/bind/irs/dns.c
lib/bind/irs/dns_ho.c
lib/bind/irs/gai_strerror.c
lib/bind/irs/gen_ho.c
lib/bind/irs/getaddrinfo.c
lib/bind/irs/irp.c
lib/bind/irs/irp_nw.c
lib/bind/irs/irpmarshall.c
lib/bind/irs/irs_data.c
lib/bind/irs/lcl_ho.c
lib/bind/irs/lcl_pr.c
lib/bind/isc/ev_connects.c
lib/bind/isc/eventlib.c
lib/bind/isc/eventlib_p.h
lib/bind/isc/heap.c
lib/bind/nameser/ns_sign.c
lib/bind/nameser/ns_verify.c
lib/bind/resolv/mtctxres.c
lib/bind/resolv/res_sendsigned.c
lib/dns/masterdump.c

diff --git a/CHANGES b/CHANGES
index b94c56fdf7aa404ee0ba2482cd5cc527b3f7f5b9..673861a8fa7a2f0bbb036f7d39c5548ba2a76c99 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,5 @@
+2009.  [bug]           libbind: coverity fixes. [RT #15808]
+
 2005.  [bug]           libbind: Retransmission timeouts should be
                        based on which attempt it is to the nameserver
                        and not the nameserver itself. [RT #13548]
index cd173ecae7eba319f467864bc9fb70148e7befb8..e042808923d0c465d5e5a898b7378e982efc5331 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef LINT
-static const char rcsid[] = "$Header: /u0/home/explorer/proj/ISC/git-conversion/cvsroot/bind9/lib/bind/dst/Attic/dst_api.c,v 1.4.2.6.8.3 2005/10/11 00:48:14 marka Exp $";
+static const char rcsid[] = "$Header: /u0/home/explorer/proj/ISC/git-conversion/cvsroot/bind9/lib/bind/dst/Attic/dst_api.c,v 1.4.2.6.8.4 2006/03/10 00:17:21 marka Exp $";
 #endif
 
 /*
@@ -170,6 +170,10 @@ dst_s_get_key_struct(const char *name, const int alg, const int flags,
 
        memset(new_key, 0, sizeof(*new_key));
        new_key->dk_key_name = strdup(name);
+       if (new_key->dk_key_name == NULL) {
+               free(new_key);
+               return (NULL);
+       }
        new_key->dk_alg = alg;
        new_key->dk_flags = flags;
        new_key->dk_proto = protocol;
@@ -655,11 +659,13 @@ dst_dnskey_to_key(const char *in_name, const u_char *rdata, const int len)
                         alg));
                return (NULL);
        }
-       if ((key_st = dst_s_get_key_struct(in_name, alg, 0, 0, 0)) == NULL)
-               return (NULL);
 
        if (in_name == NULL)
                return (NULL);
+
+       if ((key_st = dst_s_get_key_struct(in_name, alg, 0, 0, 0)) == NULL)
+               return (NULL);
+
        key_st->dk_id = dst_s_dns_key_id(rdata, len);
        key_st->dk_flags = dst_s_get_int16(rdata);
        key_st->dk_proto = (u_int16_t) rdata[DST_KEY_PROT];
@@ -772,13 +778,11 @@ dst_buffer_to_key(const char *key_name,           /* name of the key */
                return (NULL);
        }
 
-       dkey = dst_s_get_key_struct(key_name, alg, flags, 
-                                            protocol, -1);
+       dkey = dst_s_get_key_struct(key_name, alg, flags, protocol, -1);
 
-       if (dkey == NULL)
-               return (NULL);
-       if (dkey->dk_func == NULL || dkey->dk_func->from_dns_key == NULL)
-               return NULL;
+       if (dkey == NULL || dkey->dk_func == NULL ||
+           dkey->dk_func->from_dns_key == NULL) 
+               return (dst_free_key(dkey));
 
        if (dkey->dk_func->from_dns_key(dkey, key_buf, key_len) < 0) {
                EREPORT(("dst_buffer_to_key(): dst_buffer_to_hmac failed\n"));
@@ -1013,7 +1017,6 @@ dst_free_key(DST_KEY *f_key)
        else {
                EREPORT(("dst_free_key(): Unknown key alg %d\n",
                         f_key->dk_alg));
-               free(f_key->dk_KEY_struct);     /* SHOULD NOT happen */
        }
        if (f_key->dk_KEY_struct) {
                free(f_key->dk_KEY_struct);
index 2e211907627cf18052b8bfc6c831533fa778f5fd..562129975b5b06654bc7e1ee4f268bd3be3f9b5d 100644 (file)
@@ -1,6 +1,6 @@
 #ifdef HMAC_MD5
 #ifndef LINT
-static const char rcsid[] = "$Header: /u0/home/explorer/proj/ISC/git-conversion/cvsroot/bind9/lib/bind/dst/Attic/hmac_link.c,v 1.2.2.1.4.1 2005/07/28 07:43:16 marka Exp $";
+static const char rcsid[] = "$Header: /u0/home/explorer/proj/ISC/git-conversion/cvsroot/bind9/lib/bind/dst/Attic/hmac_link.c,v 1.2.2.1.4.2 2006/03/10 00:17:21 marka Exp $";
 #endif
 /*
  * Portions Copyright (c) 1995-1998 by Trusted Information Systems, Inc.
@@ -93,6 +93,9 @@ dst_hmac_md5_sign(const int mode, DST_KEY *d_key, void **context,
        int sign_len = 0;
        MD5_CTX *ctx = NULL;
 
+       if (d_key == NULL || d_key->dk_KEY_struct == NULL)
+               return (-1);
+
        if (mode & SIG_MODE_INIT) 
                ctx = (MD5_CTX *) malloc(sizeof(*ctx));
        else if (context)
@@ -100,8 +103,6 @@ dst_hmac_md5_sign(const int mode, DST_KEY *d_key, void **context,
        if (ctx == NULL) 
                return (-1);
 
-       if (d_key == NULL || d_key->dk_KEY_struct == NULL)
-               return (-1);
        key = (HMAC_Key *) d_key->dk_KEY_struct;
 
        if (mode & SIG_MODE_INIT) {
@@ -160,6 +161,9 @@ dst_hmac_md5_verify(const int mode, DST_KEY *d_key, void **context,
        HMAC_Key *key;
        MD5_CTX *ctx = NULL;
 
+       if (d_key == NULL || d_key->dk_KEY_struct == NULL)
+               return (-1);
+
        if (mode & SIG_MODE_INIT) 
                ctx = (MD5_CTX *) malloc(sizeof(*ctx));
        else if (context)
@@ -167,9 +171,6 @@ dst_hmac_md5_verify(const int mode, DST_KEY *d_key, void **context,
        if (ctx == NULL) 
                return (-1);
 
-       if (d_key == NULL || d_key->dk_KEY_struct == NULL)
-               return (-1);
-
        key = (HMAC_Key *) d_key->dk_KEY_struct;
        if (mode & SIG_MODE_INIT) {
                MD5Init(ctx);
@@ -272,7 +273,7 @@ dst_buffer_to_hmac_md5(DST_KEY *dkey, const u_char *key, const int keylen)
 
 static int
 dst_hmac_md5_key_to_file_format(const DST_KEY *dkey, char *buff,
-                           const int buff_len)
+                               const int buff_len)
 {
        char *bp;
        int len, b_len, i, key_len;
@@ -289,7 +290,7 @@ dst_hmac_md5_key_to_file_format(const DST_KEY *dkey, char *buff,
        /* write file header */
        sprintf(buff, key_file_fmt_str, KEY_FILE_FORMAT, KEY_HMAC_MD5, "HMAC");
 
-       bp = (char *) strchr(buff, '\0');
+       bp = buff + strlen(buff);
        b_len = buff_len - (bp - buff);
 
        memset(key, 0, HMAC_LEN);
@@ -334,9 +335,9 @@ dst_hmac_md5_key_from_file_format(DST_KEY *dkey, const char *buff,
 {
        const char *p = buff, *eol;
        u_char key[HMAC_LEN+1]; /* b64_pton needs more than 64 bytes do decode
-                                                        * it should probably be fixed rather than doing
-                                                        * this
-                                                        */
+                                * it should probably be fixed rather than doing
+                                * this
+                                */
        u_char *tmp;
        int key_len, len;
 
@@ -355,6 +356,8 @@ dst_hmac_md5_key_from_file_format(DST_KEY *dkey, const char *buff,
                return (-4);
        len = eol - p;
        tmp = malloc(len + 2);
+       if (tmp == NULL)
+               return (-5);
        memcpy(tmp, p, len);
        *(tmp + len) = 0x0;
        key_len = b64_pton((char *)tmp, key, HMAC_LEN+1);       /* see above */
index ab83b3e4a497d5d62b23b76d308cc38e404a169b..27529b5650652c2312572f47fb3b0ecc0bb8d476 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: dns.c,v 1.1.206.2 2004/03/17 00:29:47 marka Exp $";
+static const char rcsid[] = "$Id: dns.c,v 1.1.206.3 2006/03/10 00:17:21 marka Exp $";
 #endif
 
 /*
@@ -114,7 +114,7 @@ dns_res_get(struct irs_acc *this) {
                res = (struct __res_state *)malloc(sizeof *res);
                if (res == NULL)
                        return (NULL);
-               memset(dns->res, 0, sizeof *dns->res);
+               memset(res, 0, sizeof *res);
                dns_res_set(this, res, free);
        }
 
index 26633d607ff5d44cf010f3f421abd119500e1b06..192be042e0b9be2f58d8eb62db541ec2f8c3f350 100644 (file)
@@ -52,7 +52,7 @@
 /* BIND Id: gethnamaddr.c,v 8.15 1996/05/22 04:56:30 vixie Exp $ */
 
 #if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: dns_ho.c,v 1.5.2.7.4.7 2006/03/08 03:43:44 marka Exp $";
+static const char rcsid[] = "$Id: dns_ho.c,v 1.5.2.7.4.8 2006/03/10 00:17:21 marka Exp $";
 #endif /* LIBC_SCCS and not lint */
 
 /* Imports. */
@@ -218,8 +218,7 @@ ho_close(struct irs_ho *this) {
        ho_minimize(this);
        if (pvt->res && pvt->free_res)
                (*pvt->free_res)(pvt->res);
-       if (pvt)
-               memput(pvt, sizeof *pvt);
+       memput(pvt, sizeof *pvt);
        memput(this, sizeof *this);
 }
 
@@ -649,10 +648,9 @@ ho_addrinfo(struct irs_ho *this, const char *name, const struct addrinfo *pai)
                if (ai) {
                        querystate = RESQRY_SUCCESS;
                        cur->ai_next = ai;
-                       while (cur && cur->ai_next)
+                       while (cur->ai_next)
                                cur = cur->ai_next;
-               }
-               else
+               } else
                        querystate = RESQRY_FAIL;
        }
 
@@ -948,7 +946,7 @@ gethostans(struct irs_ho *this,
                                continue;
                        }
                        if (ret_aip) { /* need addrinfo. keep it. */
-                               while (cur && cur->ai_next)
+                               while (cur->ai_next)
                                        cur = cur->ai_next;
                        } else if (cur->ai_next) { /* need hostent */
                                struct addrinfo *aip = cur->ai_next;
index 6aeaaa1910b574b51f0e304416afdaa634c5bb80..0492f8f49aa8d9a9a1c1c873223a89509ccf53cd 100644 (file)
@@ -66,18 +66,26 @@ gai_strerror(int ecode) {
 
 #ifdef DO_PTHREADS
         if (!once) {
-                pthread_mutex_lock(&lock);
-                if (!once++)
-                        pthread_key_create(&key, free);
-                pthread_mutex_unlock(&lock);
+                if (pthread_mutex_lock(&lock) != 0)
+                       goto unknown;
+                if (!once) {
+                        if (pthread_key_create(&key, free) != 0)
+                               goto unknown;
+                       once = 1;
+               }
+                if (pthread_mutex_unlock(&lock) != 0)
+                       goto unknown;
         }
 
        buf = pthread_getspecific(key);
         if (buf == NULL) {
                buf = malloc(EAI_BUFSIZE);
                 if (buf == NULL)
-                        return ("unknown error");
-                pthread_setspecific(key, buf);
+                        goto unknown;
+                if (pthread_setspecific(key, buf) != 0) {
+                       free(buf);
+                       goto unknown;
+               }
         }
 #endif
        /* 
@@ -86,4 +94,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
 }
index e9e2c89097641926f174768db332ad7f64d976de..f17aa2238fc549c389a5109423531029d4f44b85 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: gen_ho.c,v 1.1.206.2 2004/03/17 01:49:39 marka Exp $";
+static const char rcsid[] = "$Id: gen_ho.c,v 1.1.206.3 2006/03/10 00:17:21 marka Exp $";
 #endif /* LIBC_SCCS and not lint */
 
 /* Imports */
@@ -371,8 +371,6 @@ ho_addrinfo(struct irs_ho *this, const char *name, const struct addrinfo *pai)
        }
        if (softerror != 0 && pvt->res->res_h_errno == HOST_NOT_FOUND)
                RES_SET_H_ERRNO(pvt->res, therrno);
-       if (rval)
-               freeaddrinfo(rval);
        return (NULL);
 }
 
index d80f298bf266ad0e3d898cee472a330853cedf57..39617e46ca78c8dfe300efdba60dc0be0b1e0fc2 100644 (file)
@@ -576,10 +576,6 @@ getaddrinfo(hostname, servname, hints, res)
 
        freeaddrinfo(afai);     /* afai must not be NULL at this point. */
 
-       /* we must not have got any errors. */
-       if (error != 0) /* just for diagnosis */
-               abort();
-
        if (sentinel.ai_next) {
 good:
                *res = sentinel.ai_next;
@@ -804,7 +800,7 @@ explore_numeric(pai, hostname, servname, res)
                            pai->ai_family == PF_UNSPEC /*?*/) {
                                GET_AI(cur->ai_next, afd, pton);
                                GET_PORT(cur->ai_next, servname);
-                               while (cur && cur->ai_next)
+                               while (cur->ai_next)
                                        cur = cur->ai_next;
                        } else
                                ERR(EAI_FAMILY);        /*xxx*/
@@ -817,7 +813,7 @@ explore_numeric(pai, hostname, servname, res)
                            pai->ai_family == PF_UNSPEC /*?*/) {
                                GET_AI(cur->ai_next, afd, pton);
                                GET_PORT(cur->ai_next, servname);
-                               while (cur && cur->ai_next)
+                               while (cur->ai_next)
                                        cur = cur->ai_next;
                        } else
                                ERR(EAI_FAMILY);        /*xxx*/
@@ -1202,7 +1198,7 @@ hostent2addrinfo(hp, pai)
                         */
                        GET_CANONNAME(cur->ai_next, hp->h_name);
                }
-               while (cur && cur->ai_next) /* no need to loop, actually. */
+               while (cur->ai_next) /* no need to loop, actually. */
                        cur = cur->ai_next;
                continue;
 
index 892c336a941fb4304bd2db39d3e31354231c8589..649079c31f1c2931f4a657036fc0d702a8962829 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #if !defined(LINT) && !defined(CODECENTER)
-static const char rcsid[] = "$Id: irp.c,v 1.3.2.1.10.3 2006/02/26 23:03:52 marka Exp $";
+static const char rcsid[] = "$Id: irp.c,v 1.3.2.1.10.4 2006/03/10 00:17:21 marka Exp $";
 #endif
 
 /* Imports */
@@ -425,6 +425,9 @@ irs_irp_read_body(struct irp_p *pvt, size_t *size) {
        char *buffer = memget(len);
        int idx = 0;
 
+       if (buffer == NULL)
+               return (NULL);
+
        for (;;) {
                if (irs_irp_read_line(pvt, line, sizeof line) <= 0 ||
                    strchr(line, '\n') == NULL)
index 346e5a4d80021b6b86a3bc9ab55e26526c8f623a..ea68612419808f88e41f387c616d8feb652be6ed 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: irp_nw.c,v 1.1.206.1 2004/03/09 08:33:37 marka Exp $";
+static const char rcsid[] = "$Id: irp_nw.c,v 1.1.206.2 2006/03/10 00:17:21 marka Exp $";
 #endif /* LIBC_SCCS and not lint */
 
 #if 0
@@ -319,6 +319,8 @@ nw_next(struct irs_nw *this) {
                nw = NULL;
        }
 
+       if (body != NULL)
+               memput(body, bodylen);
        return (nw);
 }
 
index 6d2ebd484334636241bc979814e70de5feee556d..198e349d5392951d03f8ea1a5ccf5a8d96152a45 100644 (file)
@@ -49,7 +49,7 @@
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: irpmarshall.c,v 1.3.206.3 2004/03/17 01:13:34 marka Exp $";
+static const char rcsid[] = "$Id: irpmarshall.c,v 1.3.206.4 2006/03/10 00:17:21 marka Exp $";
 #endif /* LIBC_SCCS and not lint */
 
 #if 0
@@ -1020,7 +1020,7 @@ irp_unmarshall_ho(struct hostent *ho, char *buffer) {
        int hoaddrtype;
        int holength;
        long t;
-       char *name = NULL;
+       char *name;
        char **aliases = NULL;
        char **hohaddrlist = NULL;
        size_t hoaddrsize;
@@ -1143,6 +1143,7 @@ irp_unmarshall_ho(struct hostent *ho, char *buffer) {
        errno = myerrno;
 
        if (name != NULL) free(name);
+       free_array(hohaddrlist, 0);
        free_array(aliases, 0);
 
        return (-1);
@@ -1313,7 +1314,6 @@ irp_unmarshall_ng(const char **hostp, const char **userp, const char **domainp,
 
        if (host != NULL) free(host);
        if (user != NULL) free(user);
-       if (domain != NULL) free(domain);
 
        return (-1);
 }
index f8e65adfe6f3e8ced21e434005c58916b07289ff..7904286db87ff35f56870ff8f363ae2262cddaa1 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #if !defined(LINT) && !defined(CODECENTER)
-static const char rcsid[] = "$Id: irs_data.c,v 1.3.2.2.4.3 2004/11/30 01:15:43 marka Exp $";
+static const char rcsid[] = "$Id: irs_data.c,v 1.3.2.2.4.4 2006/03/10 00:17:21 marka Exp $";
 #endif
 
 #include "port_before.h"
@@ -128,10 +128,15 @@ 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)
+                               return (NULL);
+                       once = 1;
+               }
+               if (pthread_mutex_unlock(&keylock) != 0)
+                       return (NULL);
        }
        net_data = pthread_getspecific(key);
 #endif
@@ -141,7 +146,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
        }
 
index 45d267782021f8a9c59616f7ba06e21dfd845d15..b59a10468f669ecae8eecd0d7f9585b8f2f3ae2a 100644 (file)
@@ -52,7 +52,7 @@
 /* BIND Id: gethnamaddr.c,v 8.15 1996/05/22 04:56:30 vixie Exp $ */
 
 #if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: lcl_ho.c,v 1.1.206.2 2004/03/17 00:29:50 marka Exp $";
+static const char rcsid[] = "$Id: lcl_ho.c,v 1.1.206.3 2006/03/10 00:17:21 marka Exp $";
 #endif /* LIBC_SCCS and not lint */
 
 /* Imports. */
@@ -541,7 +541,7 @@ ho_addrinfo(struct irs_ho *this, const char *name, const struct addrinfo *pai)
                ai = hostent2addrinfo(hp, pai);
                if (ai) {
                        cur->ai_next = ai;
-                       while (cur && cur->ai_next)
+                       while (cur->ai_next)
                                cur = cur->ai_next;
                }
        }
index d8f909e89f98b49d9c8294295b4f55b14c7678b3..ddc92c89bd6f2f5a9c48563c3d4c25a1df6bffc3 100644 (file)
@@ -49,7 +49,7 @@
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: lcl_pr.c,v 1.1.206.1 2004/03/09 08:33:38 marka Exp $";
+static const char rcsid[] = "$Id: lcl_pr.c,v 1.1.206.2 2006/03/10 00:17:21 marka Exp $";
 #endif /* LIBC_SCCS and not lint */
 
 /* extern */
@@ -85,6 +85,7 @@ static const char rcsid[] = "$Id: lcl_pr.c,v 1.1.206.1 2004/03/09 08:33:38 marka
 struct pvt {
        FILE *          fp;
        char            line[BUFSIZ+1];
+       char *          dbuf;
        struct protoent proto;
        char *          proto_aliases[MAXALIASES];
 };
@@ -141,6 +142,8 @@ pr_close(struct irs_pr *this) {
 
        if (pvt->fp)
                (void) fclose(pvt->fp);
+       if (pvt->dbuf)
+               free(pvt->dbuf);
        memput(pvt, sizeof *pvt);
        memput(this, sizeof *this);
 }
@@ -202,6 +205,10 @@ pr_next(struct irs_pr *this) {
                pr_rewind(this);
        if (!pvt->fp)
                return (NULL);
+       if (pvt->dbuf) {
+               free(pvt->dbuf);
+               pvt->dbuf = NULL;
+       }
        bufp = pvt->line;
        bufsiz = BUFSIZ;
        offset = 0;
@@ -270,6 +277,7 @@ pr_next(struct irs_pr *this) {
                }
        }
        *q = NULL;
+       pvt->dbuf = dbuf;
        return (&pvt->proto);
 }
 
index 4b0dd2222a0f026f63917ef86610778fe9c599ba..b3873b72e83c44777ec0bfd5589e93e74fea7e7b 100644 (file)
@@ -20,7 +20,7 @@
  */
 
 #if !defined(LINT) && !defined(CODECENTER)
-static const char rcsid[] = "$Id: ev_connects.c,v 1.4.206.2 2005/07/08 04:52:54 marka Exp $";
+static const char rcsid[] = "$Id: ev_connects.c,v 1.4.206.3 2006/03/10 00:17:21 marka Exp $";
 #endif
 
 /* Import. */
@@ -69,7 +69,7 @@ evListen(evContext opaqueCtx, int fd, int maxconn,
 
        OKNEW(new);
        new->flags = EV_CONN_LISTEN;
-       OK(mode = fcntl(fd, F_GETFL, NULL));    /* side effect: validate fd. */
+       OKFREE(mode = fcntl(fd, F_GETFL, NULL), new);   /* side effect: validate fd. */
        /*
         * Remember the nonblocking status.  We assume that either evSelectFD
         * has not been done to this fd, or that if it has then the caller
@@ -80,13 +80,13 @@ evListen(evContext opaqueCtx, int fd, int maxconn,
        if ((mode & PORT_NONBLOCK) == 0) {
 #ifdef USE_FIONBIO_IOCTL
                int on = 1;
-               OK(ioctl(fd, FIONBIO, (char *)&on));
+               OKFREE(ioctl(fd, FIONBIO, (char *)&on), new);
 #else
-               OK(fcntl(fd, F_SETFL, mode | PORT_NONBLOCK));
+               OKFREE(fcntl(fd, F_SETFL, mode | PORT_NONBLOCK), new);
 #endif
                new->flags |= EV_CONN_BLOCK;
        }
-       OK(listen(fd, maxconn));
+       OKFREE(listen(fd, maxconn), new);
        if (evSelectFD(opaqueCtx, fd, EV_READ, listener, new, &new->file) < 0){
                int save = errno;
 
index 77b14144b97b835142eb0786676c4716b65f0cf5..11120ecadd5de60023b5aa75f3230db1ff43f99f 100644 (file)
@@ -20,7 +20,7 @@
  */
 
 #if !defined(LINT) && !defined(CODECENTER)
-static const char rcsid[] = "$Id: eventlib.c,v 1.2.2.1.4.5 2005/07/28 07:43:20 marka Exp $";
+static const char rcsid[] = "$Id: eventlib.c,v 1.2.2.1.4.6 2006/03/10 00:17:21 marka Exp $";
 #endif
 
 #include "port_before.h"
@@ -784,13 +784,10 @@ pselect(int nfds, void *rfds, void *wfds, void *efds,
                pnfds = 0;
        }
        n = poll(fds, pnfds, polltimeout);
-       /*
-        * pselect() should return the total number of events on the file
-        * desriptors, not just the count of fd:s with activity. Hence,
-        * traverse the pollfds array and count the events.
-        */
        if (n > 0) {
                int     i, e;
+
+               INSIST(ctx != NULL);
                for (e = 0, i = ctx->firstfd; i <= ctx->fdMax; i++) {
                        if (ctx->pollfds[i].fd < 0)
                                continue;
index b95741d7aff32d4358e21ffc3b9e10e7691bb073..5c45ab83f60fe3c3910cfaec5c6ed560519e4c1d 100644 (file)
@@ -18,7 +18,7 @@
 /* eventlib_p.h - private interfaces for eventlib
  * vix 09sep95 [initial]
  *
- * $Id: eventlib_p.h,v 1.3.2.1.4.3 2005/07/28 07:43:20 marka Exp $
+ * $Id: eventlib_p.h,v 1.3.2.1.4.4 2006/03/10 00:17:21 marka Exp $
  */
 
 #ifndef _EVENTLIB_P_H
@@ -45,6 +45,8 @@
 #define        EV_MASK_ALL     (EV_READ | EV_WRITE | EV_EXCEPT)
 #define EV_ERR(e)              return (errno = (e), -1)
 #define OK(x)          if ((x) < 0) EV_ERR(errno); else (void)NULL
+#define OKFREE(x, y)   if ((x) < 0) { FREE((y)); EV_ERR(errno); } \
+                       else (void)NULL
 
 #define        NEW(p)          if (((p) = memget(sizeof *(p))) != NULL) \
                                FILL(p); \
index f63619f5688ff7296d5130c8dd7994e6bb1f8b3d..2faf6f5767f0a2c1de592643c07b688f9352eb26 100644 (file)
@@ -26,7 +26,7 @@
  */
 
 #if !defined(LINT) && !defined(CODECENTER)
-static const char rcsid[] = "$Id: heap.c,v 1.1.206.1 2004/03/09 08:33:43 marka Exp $";
+static const char rcsid[] = "$Id: heap.c,v 1.1.206.2 2006/03/10 00:17:21 marka Exp $";
 #endif /* not lint */
 
 #include "port_before.h"
@@ -54,9 +54,13 @@ heap_new(heap_higher_priority_func higher_priority, heap_index_func index,
         int array_size_increment) {
        heap_context ctx;
 
+       if (higher_priority == NULL)
+               return (NULL);
+
        ctx = (heap_context)malloc(sizeof (struct heap_context));
-       if (ctx == NULL || higher_priority == NULL)
+       if (ctx == NULL)
                return (NULL);
+
        ctx->array_size = 0;
        if (array_size_increment == 0)
                ctx->array_size_increment = ARRAY_SIZE_INCREMENT;
index 56248a59a800842336f14114b20e20ee2171f0a0..7b742f1f5f1791b4a6080307974953686346a24b 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: ns_sign.c,v 1.1.2.2.4.1 2004/03/09 08:33:45 marka Exp $";
+static const char rcsid[] = "$Id: ns_sign.c,v 1.1.2.2.4.2 2006/03/10 00:17:21 marka Exp $";
 #endif
 
 /* Import. */
@@ -89,7 +89,7 @@ ns_sign2(u_char *msg, int *msglen, int msgsize, int error, void *k,
 {
        HEADER *hp = (HEADER *)msg;
        DST_KEY *key = (DST_KEY *)k;
-       u_char *cp = msg + *msglen, *eob = msg + msgsize;
+       u_char *cp, *eob;
        u_char *lenp;
        u_char *alg;
        int n;
@@ -100,6 +100,9 @@ ns_sign2(u_char *msg, int *msglen, int msgsize, int error, void *k,
        if (msg == NULL || msglen == NULL || sig == NULL || siglen == NULL)
                return (-1);
 
+       cp = msg + *msglen;
+       eob = msg + msgsize;
+
        /* Name. */
        if (key != NULL && error != ns_r_badsig && error != ns_r_badkey) {
                n = ns_name_pton(key->dk_key_name, name, sizeof name);
index adda249bb4c354eb726a261f9d4d91fb2e085fc7..c74a0a38b24762977faf4d63fcc1c4d5e457c0aa 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: ns_verify.c,v 1.1.206.2 2005/10/11 00:48:16 marka Exp $";
+static const char rcsid[] = "$Id: ns_verify.c,v 1.1.206.3 2006/03/10 00:17:21 marka Exp $";
 #endif
 
 /* Import. */
@@ -343,7 +343,7 @@ ns_verify_tcp(u_char *msg, int *msglen, ns_tcp_tsig_state *state,
        HEADER *hp = (HEADER *)msg;
        u_char *recstart, *sigstart;
        unsigned int sigfieldlen, otherfieldlen;
-       u_char *cp, *eom = msg + *msglen, *cp2;
+       u_char *cp, *eom, *cp2;
        char name[MAXDNAME], alg[MAXDNAME];
        u_char buf[MAXDNAME];
        int n, type, length, fudge, error;
@@ -352,6 +352,8 @@ ns_verify_tcp(u_char *msg, int *msglen, ns_tcp_tsig_state *state,
        if (msg == NULL || msglen == NULL || state == NULL)
                return (-1);
 
+       eom = msg + *msglen;
+
        state->counter++;
        if (state->counter == 0)
                return (ns_verify(msg, msglen, state->key,
index f33cf11e3f42ddeffc5d1b5b5b11eb1285216693..635bbd4400f456a50a588ce84a0705b5fb31149f 100644 (file)
@@ -106,9 +106,10 @@ ___mtctxres(void) {
         */
        if (!mt_key_initialized) {
                static pthread_mutex_t keylock = PTHREAD_MUTEX_INITIALIZER;
-                pthread_mutex_lock(&keylock);
-               _mtctxres_init();
-                pthread_mutex_unlock(&keylock);
+                if (pthread_mutex_lock(&keylock) == 0) {
+                       _mtctxres_init();
+                       (void) pthread_mutex_unlock(&keylock);
+               }
        }
 
        /*
index d1d22745756694bbb0cc1c3e4b546a0a48e61320..93ad5c979579e5429bb0a6f771d86033b4a047f1 100644 (file)
@@ -52,6 +52,7 @@ res_nsendsigned(res_state statp, const u_char *msg, int msglen,
        bufsize = msglen + 1024;
        newmsg = (u_char *) malloc(bufsize);
        if (newmsg == NULL) {
+               free(nstatp);
                errno = ENOMEM;
                return (-1);
        }
@@ -102,11 +103,11 @@ res_nsendsigned(res_state statp, const u_char *msg, int msglen,
 retry:
 
        len = res_nsend(nstatp, newmsg, newmsglen, answer, anslen);
-       if (ret < 0) {
+       if (len < 0) {
                free (nstatp);
                free (newmsg);
                dst_free_key(dstkey);
-               return (ret);
+               return (len);
        }
 
        ret = ns_verify(answer, &len, dstkey, sig, siglen,
index 54a2c6d7d24f8da491670937516b3daf7e6554fd..0f4716d583d975a1e6137038e7469956b6e722e5 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: masterdump.c,v 1.56.2.5.2.14 2006/01/04 23:50:20 marka Exp $ */
+/* $Id: masterdump.c,v 1.56.2.5.2.15 2006/03/10 00:17:21 marka Exp $ */
 
 #include <config.h>
 
@@ -1160,7 +1160,8 @@ dumptostreaminc(dns_dumpctx_t *dctx) {
        }
 
        if (dctx->nodes != 0 && result == ISC_R_SUCCESS) {
-               dns_dbiterator_pause(dctx->dbiter);
+               result = dns_dbiterator_pause(dctx->dbiter);
+               RUNTIME_CHECK(result == ISC_R_SUCCESS);
                result = DNS_R_CONTINUE;
        } else if (result == ISC_R_NOMORE)
                result = ISC_R_SUCCESS;