]> 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:20:08 +0000 (00:20 +0000)
committerMark Andrews <marka@isc.org>
Fri, 10 Mar 2006 00:20:08 +0000 (00:20 +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 af21cfece29db3a8205b3d35ae5c529dc976dd13..a4efc9528ad5b6543154a6f6638e7ec73ce953fe 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,5 @@
+2009.  [bug]           libbind: coverity fixes. [RT #15808]
+
 2008.  [func]          It is now posssible to enable/disable DNSSEC
                        validation from rndc.  This is useful for the
                        mobile hosts where the current connection point
index 4391dd8c05db635eb767747d1663c919de93f24b..548f9437f13044be19f68cf1e275c43fb0552244 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.10.332.4 2005/10/11 00:25:08 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.10.332.5 2006/03/10 00:20:08 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;
@@ -649,11 +653,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];
@@ -764,13 +770,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"));
@@ -1003,7 +1007,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 e0524521e6df2efc28656ff0fe9fde86fe7d22a8..5f1370f3a58217623faa8c206446701e3acd7d6b 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.3.164.2 2005/07/28 07:38:06 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.3.164.3 2006/03/10 00:20:08 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;
@@ -288,7 +289,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);
@@ -333,9 +334,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;
 
@@ -354,6 +355,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 ad46b8ca9494daf77fb1c4c33c0411b90855d5c6..b78a1d6708b8eebba3432fcbd2e754b222fe20b3 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: dns.c,v 1.3.18.1 2005/04/27 05:00:54 sra Exp $";
+static const char rcsid[] = "$Id: dns.c,v 1.3.18.2 2006/03/10 00:20:08 marka Exp $";
 #endif
 
 /*! \file
@@ -115,7 +115,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 3e93852b8ecdaa458c7bd561ac68e9847bd917cc..7d265b31ca9dfdcbe9a027ff149bdadbcee9c744 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.14.18.5 2006/03/08 03:43:18 marka Exp $";
+static const char rcsid[] = "$Id: dns_ho.c,v 1.14.18.6 2006/03/10 00:20:08 marka Exp $";
 #endif /* LIBC_SCCS and not lint */
 
 /* Imports. */
@@ -216,8 +216,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);
 }
 
@@ -645,10 +644,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;
        }
 
@@ -944,7 +942,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 dc2e3417490e6b0287abd0f97e9c9b62728a03d7..29196a0a157db7b5de15face3cd687cd25beeb80 100644 (file)
@@ -65,18 +65,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
        /* 
@@ -85,6 +93,11 @@ gai_strerror(int ecode) {
         */
        sprintf(buf, "%s: %d", gai_errlist[gai_nerr - 1], ecode);
        return (buf);
+
+#ifdef DO_PTHREADS
+ unknown:
+       return ("unknown error");
+#endif
 }
 
 /*! \file */
index 38fde25b0fb206b6dc9afa3d40f7afa5438a432e..c5e09daede35c14688e2701ee32c17d444982986 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: gen_ho.c,v 1.3.18.1 2005/04/27 05:00:56 sra Exp $";
+static const char rcsid[] = "$Id: gen_ho.c,v 1.3.18.2 2006/03/10 00:20:08 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 a1ea15d6843b93786746162c0ab031f8dbf49668..e27037c9a251ebccb8608774703dc2485d83b3be 100644 (file)
@@ -579,9 +579,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:
@@ -807,7 +804,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*/
@@ -820,7 +817,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*/
@@ -1204,7 +1201,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 72f0c1e8e2078d110bc8bf5c102eb4d3dd4bf15f..85a053d7e6f8ea397fdd07c5693de22966548307 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #if !defined(LINT) && !defined(CODECENTER)
-static const char rcsid[] = "$Id: irp.c,v 1.6.18.2 2006/02/26 22:59:56 marka Exp $";
+static const char rcsid[] = "$Id: irp.c,v 1.6.18.3 2006/03/10 00:20:08 marka Exp $";
 #endif
 
 /* Imports */
@@ -414,6 +414,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 a3e51049a4ff8f03926eaf1216757ea577a6cfd6..b285120c958c097dd35bfd151d3f6b15692380ed 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: irp_nw.c,v 1.2.18.1 2005/04/27 05:01:00 sra Exp $";
+static const char rcsid[] = "$Id: irp_nw.c,v 1.2.18.2 2006/03/10 00:20:08 marka Exp $";
 #endif /* LIBC_SCCS and not lint */
 
 #if 0
@@ -297,6 +297,8 @@ nw_next(struct irs_nw *this) {
                nw = NULL;
        }
 
+       if (body != NULL)
+               memput(body, bodylen);
        return (nw);
 }
 
index ae25e4e893d3c89295acd939ed9ae4947d0baf21..8c34fa26db54b8aa5ae3d88657f359e347338b00 100644 (file)
@@ -49,7 +49,7 @@
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: irpmarshall.c,v 1.5.18.1 2005/04/27 05:01:01 sra Exp $";
+static const char rcsid[] = "$Id: irpmarshall.c,v 1.5.18.2 2006/03/10 00:20:08 marka Exp $";
 #endif /* LIBC_SCCS and not lint */
 
 #if 0
@@ -994,7 +994,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;
@@ -1117,6 +1117,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);
@@ -1285,7 +1286,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 c4557c9255825b62fc3ce7c9544eaa4a447c651b..b71bc33f7fd843e3cfe6dbdcde9839bc0757eb04 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #if !defined(LINT) && !defined(CODECENTER)
-static const char rcsid[] = "$Id: irs_data.c,v 1.7.18.2 2005/04/27 05:01:01 sra Exp $";
+static const char rcsid[] = "$Id: irs_data.c,v 1.7.18.3 2006/03/10 00:20:08 marka Exp $";
 #endif
 
 #include "port_before.h"
@@ -129,10 +129,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
@@ -142,7 +147,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 6759af6bc571c5cfd35dabc06f60cebec5863b6d..9534ee627e173cb5fe5cb2481b17e77d918f0a0d 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.3.18.1 2005/04/27 05:01:02 sra Exp $";
+static const char rcsid[] = "$Id: lcl_ho.c,v 1.3.18.2 2006/03/10 00:20:08 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 97cc0ae0d3e45a74b5d08c088f82ce816879af70..08c6da95e3c6806e857ef3e5113680a4ec798b45 100644 (file)
@@ -49,7 +49,7 @@
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: lcl_pr.c,v 1.2.18.1 2005/04/27 05:01:02 sra Exp $";
+static const char rcsid[] = "$Id: lcl_pr.c,v 1.2.18.2 2006/03/10 00:20:08 marka Exp $";
 #endif /* LIBC_SCCS and not lint */
 
 /* extern */
@@ -85,6 +85,7 @@ static const char rcsid[] = "$Id: lcl_pr.c,v 1.2.18.1 2005/04/27 05:01:02 sra Ex
 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 2b51223c096cc1ae97ce83e2318940973518570f..64e918d388a5ac9e1590893a142d0d7e8fe28e77 100644 (file)
@@ -20,7 +20,7 @@
  */
 
 #if !defined(LINT) && !defined(CODECENTER)
-static const char rcsid[] = "$Id: ev_connects.c,v 1.5.18.2 2005/07/08 04:40:16 marka Exp $";
+static const char rcsid[] = "$Id: ev_connects.c,v 1.5.18.3 2006/03/10 00:20:08 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 e8baa52226ebdfacc91e01812ec4f17a9dad8969..20624d0b4573908c99ef6506a347972cc128477f 100644 (file)
@@ -20,7 +20,7 @@
  */
 
 #if !defined(LINT) && !defined(CODECENTER)
-static const char rcsid[] = "$Id: eventlib.c,v 1.5.18.4 2005/07/28 07:38:09 marka Exp $";
+static const char rcsid[] = "$Id: eventlib.c,v 1.5.18.5 2006/03/10 00:20:08 marka Exp $";
 #endif
 
 #include "port_before.h"
@@ -783,13 +783,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 859a329c92eafdf6f4969207bb70d7b61de5a109..589655378a810e6fa093c9c05fa49fbaaa5aa1ac 100644 (file)
@@ -19,7 +19,7 @@
  * \brief private interfaces for eventlib
  * \author vix 09sep95 [initial]
  *
- * $Id: eventlib_p.h,v 1.5.18.3 2005/07/28 07:38:09 marka Exp $
+ * $Id: eventlib_p.h,v 1.5.18.4 2006/03/10 00:20:08 marka Exp $
  */
 
 #ifndef _EVENTLIB_P_H
@@ -46,6 +46,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 b738a3e48c6207df6640802f76c0bd3bcdc07153..bea7678df36282dd89f381b1fd847e3a95489ead 100644 (file)
@@ -26,7 +26,7 @@
  */
 
 #if !defined(LINT) && !defined(CODECENTER)
-static const char rcsid[] = "$Id: heap.c,v 1.2.18.1 2005/04/27 05:01:07 sra Exp $";
+static const char rcsid[] = "$Id: heap.c,v 1.2.18.2 2006/03/10 00:20:08 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 aecc888ba83d6762f1f3146dd3c6c78208aeda2a..ab4b0efafe26926f8065a24a020ef6fb91d1ff0c 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: ns_sign.c,v 1.4.18.1 2005/04/27 05:01:09 sra Exp $";
+static const char rcsid[] = "$Id: ns_sign.c,v 1.4.18.2 2006/03/10 00:20:08 marka Exp $";
 #endif
 
 /* Import. */
@@ -91,7 +91,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;
@@ -102,6 +102,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 d39fbd9a6e7ee2714aa3fdebf5001cbdb5fe1604..b80b588ba5b1d943a664551b2226e5745965038c 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: ns_verify.c,v 1.2.18.2 2005/10/11 00:25:11 marka Exp $";
+static const char rcsid[] = "$Id: ns_verify.c,v 1.2.18.3 2006/03/10 00:20:08 marka Exp $";
 #endif
 
 /* Import. */
@@ -344,7 +344,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;
@@ -353,6 +353,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 2a4a6efd5e001957703c315482703d463106d5ed..63ae07ce3d26b7abd3cfac692763efef57c807d4 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 7b84c5bbe37e309910221877cacb524750eeb4eb..e246104633cf5cef541b644376a1490d5aed804d 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: masterdump.c,v 1.73.18.12 2006/03/05 23:58:51 marka Exp $ */
+/* $Id: masterdump.c,v 1.73.18.13 2006/03/10 00:20:08 marka Exp $ */
 
 /*! \file */
 
@@ -1411,7 +1411,8 @@ dumptostreaminc(dns_dumpctx_t *dctx) {
                                      "dumptostreaminc(%p) new nodes -> %d\n",
                                      dctx, dctx->nodes);
                }
-               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;