+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
#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
/*
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;
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];
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"));
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);
#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.
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)
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) {
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)
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);
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;
/* 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);
{
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;
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 */
*/
#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
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);
}
/* 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. */
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);
}
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;
}
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;
#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
/*
*/
sprintf(buf, "%s: %d", gai_errlist[gai_nerr - 1], ecode);
return (buf);
+
+#ifdef DO_PTHREADS
+ unknown:
+ return ("unknown error");
+#endif
}
/*! \file */
*/
#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 */
}
if (softerror != 0 && pvt->res->res_h_errno == HOST_NOT_FOUND)
RES_SET_H_ERRNO(pvt->res, therrno);
- if (rval)
- freeaddrinfo(rval);
return (NULL);
}
}
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:
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*/
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*/
*/
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;
*/
#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 */
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)
*/
#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
nw = NULL;
}
+ if (body != NULL)
+ memput(body, bodylen);
return (nw);
}
*/
#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
int hoaddrtype;
int holength;
long t;
- char *name = NULL;
+ char *name;
char **aliases = NULL;
char **hohaddrlist = NULL;
size_t hoaddrsize;
errno = myerrno;
if (name != NULL) free(name);
+ free_array(hohaddrlist, 0);
free_array(aliases, 0);
return (-1);
if (host != NULL) free(host);
if (user != NULL) free(user);
- if (domain != NULL) free(domain);
return (-1);
}
*/
#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"
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
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
}
/* 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. */
ai = hostent2addrinfo(hp, pai);
if (ai) {
cur->ai_next = ai;
- while (cur && cur->ai_next)
+ while (cur->ai_next)
cur = cur->ai_next;
}
}
*/
#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 */
struct pvt {
FILE * fp;
char line[BUFSIZ+1];
+ char * dbuf;
struct protoent proto;
char * proto_aliases[MAXALIASES];
};
if (pvt->fp)
(void) fclose(pvt->fp);
+ if (pvt->dbuf)
+ free(pvt->dbuf);
memput(pvt, sizeof *pvt);
memput(this, sizeof *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;
}
}
*q = NULL;
+ pvt->dbuf = dbuf;
return (&pvt->proto);
}
*/
#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. */
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
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;
*/
#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"
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;
* \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
#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); \
*/
#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"
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;
*/
#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. */
{
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;
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);
*/
#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. */
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;
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,
*/
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);
+ }
}
/*
bufsize = msglen + 1024;
newmsg = (u_char *) malloc(bufsize);
if (newmsg == NULL) {
+ free(nstatp);
errno = ENOMEM;
return (-1);
}
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,
* 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 */
"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;