From a53a622417497f8db149b85802cdf620a602cdd3 Mon Sep 17 00:00:00 2001 From: Evan Hunt Date: Tue, 23 Oct 2012 22:26:23 -0700 Subject: [PATCH] [v9_8] silence coverity warnings 3401. [bug] Addressed Coverity warnings. [RT #31484] (cherry picked from commit 47c5b8af920a93763c97d9a93ea1fd766961a5b3) (cherry picked from commit 2589af58684a5994ba2e943df4ceb898942e3383) --- CHANGES | 2 + bin/check/named-checkconf.c | 1 + bin/check/named-checkzone.c | 1 + bin/named/client.c | 7 +- bin/rndc/rndc.c | 1 + bin/tests/dst/t_dst.c | 35 ++++----- bin/tests/names/t_names.c | 16 +++-- bin/tests/system/dlzexternal/driver.c | 13 ++-- bin/tools/genrandom.c | 1 + contrib/dlz/drivers/dlz_filesystem_driver.c | 44 ++++++------ lib/dns/adb.c | 2 + lib/dns/dispatch.c | 2 - lib/dns/dst_api.c | 6 +- lib/dns/name.c | 1 + lib/dns/validator.c | 10 ++- lib/dns/view.c | 13 +++- lib/dns/xfrin.c | 1 + lib/export/samples/sample-request.c | 6 +- lib/irs/getaddrinfo.c | 4 +- lib/irs/getnameinfo.c | 1 + lib/irs/resconf.c | 2 +- lib/isc/include/isc/sockaddr.h | 1 + lib/isc/inet_aton.c | 2 +- lib/isc/ratelimiter.c | 1 + lib/isc/sockaddr.c | 7 +- lib/isc/tests/Makefile.in | 13 ++-- lib/isc/tests/sockaddr_test.c | 78 +++++++++++++++++++++ lib/isc/timer.c | 2 +- lib/isc/unix/net.c | 3 - lib/lwres/context.c | 1 + lib/lwres/getipnode.c | 2 +- lib/lwres/lwinetaton.c | 2 +- lib/lwres/print.c | 4 ++ 33 files changed, 202 insertions(+), 83 deletions(-) create mode 100644 lib/isc/tests/sockaddr_test.c diff --git a/CHANGES b/CHANGES index 8adeaa66b5..e347bdf492 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,5 @@ +3401. [bug] Addressed Coverity warnings. [RT #31484] + 3400. [cleanup] "named -V" can now report a source ID string, defined in the "srcid" file in the build tree and normally set to the most recent git hash. [RT #31494] diff --git a/bin/check/named-checkconf.c b/bin/check/named-checkconf.c index a342dd9fbd..d07d48bbd8 100644 --- a/bin/check/named-checkconf.c +++ b/bin/check/named-checkconf.c @@ -471,6 +471,7 @@ main(int argc, char **argv) { if (isc_commandline_option != '?') fprintf(stderr, "%s: invalid argument -%c\n", program, isc_commandline_option); + /* FALLTHROUGH */ case 'h': usage(); diff --git a/bin/check/named-checkzone.c b/bin/check/named-checkzone.c index 11491b5808..1c08f903b1 100644 --- a/bin/check/named-checkzone.c +++ b/bin/check/named-checkzone.c @@ -374,6 +374,7 @@ main(int argc, char **argv) { if (isc_commandline_option != '?') fprintf(stderr, "%s: invalid argument -%c\n", prog_name, isc_commandline_option); + /* FALLTHROUGH */ case 'h': usage(); diff --git a/bin/named/client.c b/bin/named/client.c index 87dd0450aa..ff4ab691c1 100644 --- a/bin/named/client.c +++ b/bin/named/client.c @@ -1394,10 +1394,9 @@ client_request(isc_task_t *task, isc_event_t *event) { INSIST(client->recursionquota == NULL); - INSIST(client->state == - TCP_CLIENT(client) ? - NS_CLIENTSTATE_READING : - NS_CLIENTSTATE_READY); + INSIST(client->state == (TCP_CLIENT(client) ? + NS_CLIENTSTATE_READING : + NS_CLIENTSTATE_READY)); ns_client_requests++; diff --git a/bin/rndc/rndc.c b/bin/rndc/rndc.c index 5811cfa141..4812be7524 100644 --- a/bin/rndc/rndc.c +++ b/bin/rndc/rndc.c @@ -771,6 +771,7 @@ main(int argc, char **argv) { program, isc_commandline_option); usage(1); } + /* FALLTHROUGH */ case 'h': usage(0); break; diff --git a/bin/tests/dst/t_dst.c b/bin/tests/dst/t_dst.c index 9f4e6904e6..33dbf9f663 100644 --- a/bin/tests/dst/t_dst.c +++ b/bin/tests/dst/t_dst.c @@ -560,24 +560,26 @@ sig_fromfile(char *path, isc_buffer_t *iscbuf) { char *p; char *buf; - rval = stat(path, &sb); + fd = open(path, O_RDONLY); + if (fd < 0) { + t_info("open failed, errno == %d\n", errno); + return(1); + } + + rval = fstat(fd, &sb); if (rval != 0) { t_info("stat %s failed, errno == %d\n", path, errno); + close(fd); return(1); } buf = (char *) malloc((sb.st_size + 1) * sizeof(unsigned char)); if (buf == NULL) { t_info("malloc failed, errno == %d\n", errno); + close(fd); return(1); } - fd = open(path, O_RDONLY); - if (fd < 0) { - t_info("open failed, errno == %d\n", errno); - (void) free(buf); - return(1); - } len = sb.st_size; p = buf; @@ -651,10 +653,18 @@ t2_sigchk(char *datapath, char *sigpath, char *keyname, /* * Read data from file in a form usable by dst_verify. */ - rval = stat(datapath, &sb); + fd = open(datapath, O_RDONLY); + if (fd < 0) { + t_info("t2_sigchk: open failed %d\n", errno); + ++*nprobs; + return; + } + + rval = fstat(fd, &sb); if (rval != 0) { t_info("t2_sigchk: stat (%s) failed %d\n", datapath, errno); ++*nprobs; + close(fd); return; } @@ -662,14 +672,7 @@ t2_sigchk(char *datapath, char *sigpath, char *keyname, if (data == NULL) { t_info("t2_sigchk: malloc failed %d\n", errno); ++*nprobs; - return; - } - - fd = open(datapath, O_RDONLY); - if (fd < 0) { - t_info("t2_sigchk: open failed %d\n", errno); - (void) free(data); - ++*nprobs; + close(fd); return; } diff --git a/bin/tests/names/t_names.c b/bin/tests/names/t_names.c index fba5aabb63..57a29c18a7 100644 --- a/bin/tests/names/t_names.c +++ b/bin/tests/names/t_names.c @@ -185,13 +185,14 @@ chkdata(unsigned char *buf, size_t buflen, char *exp_data, * setup the buffer and return the data length. */ static int -getmsg(char *datafile_name, unsigned char *buf, int buflen, isc_buffer_t *pbuf) +getmsg(char *datafile_name, isc_buffer_t *pbuf) { int c; - int len; - int cnt; + unsigned int len; + unsigned int cnt; unsigned char *p; FILE *fp; + unsigned int buflen; fp = fopen(datafile_name, "r"); if (fp == NULL) { @@ -199,7 +200,8 @@ getmsg(char *datafile_name, unsigned char *buf, int buflen, isc_buffer_t *pbuf) return (0); } - p = buf; + p = isc_buffer_used(pbuf); + buflen = isc_buffer_availablelength(pbuf); cnt = 0; len = 0; while ((c = getc(fp)) != EOF) { @@ -248,7 +250,6 @@ getmsg(char *datafile_name, unsigned char *buf, int buflen, isc_buffer_t *pbuf) } *p = '\0'; - isc_buffer_init(pbuf, buf, cnt); isc_buffer_add(pbuf, cnt); return (cnt); } @@ -2014,7 +2015,10 @@ test_dns_name_fromwire(char *datafile_name, int testname_offset, int downcase, dns_decompress_t dctx; t_info("testing using %s\n", datafile_name); - len = getmsg(datafile_name, buf1, BIGBUFLEN, &iscbuf1); + isc_buffer_init(&iscbuf1, buf1, sizeof(buf1)); + len = getmsg(datafile_name, &iscbuf1); + if (len == 0) + return (T_FAIL); isc_buffer_setactive(&iscbuf1, len); iscbuf1.current = testname_offset; diff --git a/bin/tests/system/dlzexternal/driver.c b/bin/tests/system/dlzexternal/driver.c index 8492a924ec..88660196fc 100644 --- a/bin/tests/system/dlzexternal/driver.c +++ b/bin/tests/system/dlzexternal/driver.c @@ -122,7 +122,7 @@ add_name(struct dlz_example_data *state, struct record *list, } strcpy(list[i].name, name); strcpy(list[i].type, type); - strcpy(list[i].data, data); + strncpy(list[i].data, data, sizeof(list[i].data)); list[i].ttl = ttl; return (ISC_R_SUCCESS); } @@ -279,7 +279,7 @@ dlz_lookup(const char *zone, const char *name, void *dbdata, { struct dlz_example_data *state = (struct dlz_example_data *)dbdata; isc_boolean_t found = ISC_FALSE; - char full_name[100]; + char full_name[256]; int i; UNUSED(zone); @@ -287,10 +287,11 @@ dlz_lookup(const char *zone, const char *name, void *dbdata, if (state->putrr == NULL) return (ISC_R_NOTIMPLEMENTED); - if (strcmp(name, "@") == 0) - strcpy(full_name, state->zone_name); - else - sprintf(full_name, "%s.%s", name, state->zone_name); + if (strcmp(name, "@") == 0) { + strncpy(full_name, state->zone_name, 255); + full_name[255] = '\0'; + } else + snprintf(full_name, 255, "%s.%s", name, state->zone_name); for (i = 0; i < MAX_RECORDS; i++) { if (strcasecmp(state->current[i].name, full_name) == 0) { diff --git a/bin/tools/genrandom.c b/bin/tools/genrandom.c index 675e5043d6..23597fad8d 100644 --- a/bin/tools/genrandom.c +++ b/bin/tools/genrandom.c @@ -93,6 +93,7 @@ main(int argc, char **argv) { if (isc_commandline_option != '?') fprintf(stderr, "%s: invalid argument -%c\n", program, isc_commandline_option); + /* FALLTHROUGH */ case 'h': usage(); diff --git a/contrib/dlz/drivers/dlz_filesystem_driver.c b/contrib/dlz/drivers/dlz_filesystem_driver.c index 6dbb2cacdc..bfc143499b 100644 --- a/contrib/dlz/drivers/dlz_filesystem_driver.c +++ b/contrib/dlz/drivers/dlz_filesystem_driver.c @@ -360,7 +360,7 @@ create_path(const char *zone, const char *host, const char *client, } static isc_result_t -process_dir(isc_dir_t dir, void *passback, config_data_t *cd, +process_dir(isc_dir_t *dir, void *passback, config_data_t *cd, dlist_t *dir_list, unsigned int basedirlen) { @@ -386,10 +386,10 @@ process_dir(isc_dir_t dir, void *passback, config_data_t *cd, foundHost = ISC_FALSE; /* copy base directory name to tmp. */ - strcpy(tmp, dir.dirname); + strcpy(tmp, dir->dirname); - /* dir.dirname will always have '*' as the last char. */ - astPos = strlen(dir.dirname) - 1; + /* dir->dirname will always have '*' as the last char. */ + astPos = strlen(dir->dirname) - 1; /* if dir_list != NULL, were are performing a zone xfr */ if (dir_list != NULL) { @@ -425,46 +425,48 @@ process_dir(isc_dir_t dir, void *passback, config_data_t *cd, foundHost = ISC_TRUE; /* set tmp again for use later */ - strcpy(tmp, dir.dirname); + strcpy(tmp, dir->dirname); } } else { /* * if splitcnt != 0 determine host from * ".host" directory entry */ - while (isc_dir_read(&dir) == ISC_R_SUCCESS) { + while (isc_dir_read(dir) == ISC_R_SUCCESS) { if (strncasecmp(".host", - dir.entry.name, 5) == 0) { + dir->entry.name, 5) == 0) { /* * handle filesystem's special * wildcard "-" */ - if (strcmp((char *) &dir.entry.name[6], + if (strcmp((char *) &dir->entry.name[6], "-") == 0) strcpy(host, "*"); - else - strcpy(host, - (char *) - &dir.entry.name[6]); + else { + strncpy(host, + (char *) &dir->entry.name[6], + sizeof(host) - 1); + host[255] = '\0'; + } foundHost = ISC_TRUE; break; } } /* reset dir list for use later */ - isc_dir_reset(&dir); + isc_dir_reset(dir); } /* end of else */ } - while (isc_dir_read(&dir) == ISC_R_SUCCESS) { + while (isc_dir_read(dir) == ISC_R_SUCCESS) { isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ, ISC_LOG_DEBUG(1), "Filesystem driver Dir name:" " '%s' Dir entry: '%s'\n", - dir.dirname, dir.entry.name); + dir->dirname, dir->entry.name); /* skip any entries starting with "." */ - if (dir.entry.name[0] == '.') + if (dir->entry.name[0] == '.') continue; /* @@ -477,7 +479,7 @@ process_dir(isc_dir_t dir, void *passback, config_data_t *cd, tmp[astPos] = '\0'; /* add name to base directory name. */ - strcat(tmp, dir.entry.name); + strcat(tmp, dir->entry.name); /* make sure we can stat entry */ if (stat(tmp, &sb) == 0 ) { @@ -515,7 +517,7 @@ process_dir(isc_dir_t dir, void *passback, config_data_t *cd, } else /* if we cannot stat entry, skip it. */ continue; - type = dir.entry.name; + type = dir->entry.name; ttlStr = strchr(type, cd->separator); if (ttlStr == NULL) { isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, @@ -687,7 +689,7 @@ fs_allnodes(const char *zone, void *driverarg, void *dbdata, } /* process the directory */ - result = process_dir(dir, allnodes, cd, dir_list, basepathlen); + result = process_dir(&dir, allnodes, cd, dir_list, basepathlen); /* close the directory */ isc_dir_close(&dir); @@ -712,7 +714,7 @@ fs_allnodes(const char *zone, void *driverarg, void *dbdata, } /* process the directory */ - result = process_dir(dir, allnodes, cd, dir_list, basepathlen); + result = process_dir(&dir, allnodes, cd, dir_list, basepathlen); /* close the directory */ isc_dir_close(&dir); @@ -841,7 +843,7 @@ fs_lookup(const char *zone, const char *name, void *driverarg, } /* process any records in the directory */ - result = process_dir(dir, lookup, (config_data_t *) dbdata, NULL, 0); + result = process_dir(&dir, lookup, (config_data_t *) dbdata, NULL, 0); /* close the directory */ isc_dir_close(&dir); diff --git a/lib/dns/adb.c b/lib/dns/adb.c index 531d112e63..0872a33e44 100644 --- a/lib/dns/adb.c +++ b/lib/dns/adb.c @@ -2075,6 +2075,7 @@ copy_namehook_lists(dns_adb_t *adb, dns_adbfind_t *find, dns_name_t *qname, while (namehook != NULL) { entry = namehook->entry; bucket = entry->lock_bucket; + INSIST(bucket != DNS_ADB_INVALIDBUCKET); LOCK(&adb->entrylocks[bucket]); if (!FIND_RETURNLAME(find) @@ -2105,6 +2106,7 @@ copy_namehook_lists(dns_adb_t *adb, dns_adbfind_t *find, dns_name_t *qname, while (namehook != NULL) { entry = namehook->entry; bucket = entry->lock_bucket; + INSIST(bucket != DNS_ADB_INVALIDBUCKET); LOCK(&adb->entrylocks[bucket]); if (!FIND_RETURNLAME(find) diff --git a/lib/dns/dispatch.c b/lib/dns/dispatch.c index 60fb1e2c2b..bdd11dd9ce 100644 --- a/lib/dns/dispatch.c +++ b/lib/dns/dispatch.c @@ -2805,8 +2805,6 @@ get_udpsocket(dns_dispatchmgr_t *mgr, dns_dispatch_t *disp, result = open_socket(sockmgr, localaddr, 0, &sock); if (result != ISC_R_SUCCESS) goto end; - else if (!anyport) - break; else if (portavailable(mgr, sock, NULL)) break; if (held[i] != NULL) diff --git a/lib/dns/dst_api.c b/lib/dns/dst_api.c index f5dd89ad4f..ea975a9c7d 100644 --- a/lib/dns/dst_api.c +++ b/lib/dns/dst_api.c @@ -495,8 +495,7 @@ dst_key_fromnamedfile(const char *filename, const char *dirname, result = dst_key_read_public(newfilename, type, mctx, &pubkey); isc_mem_put(mctx, newfilename, newfilenamelen); newfilename = NULL; - if (result != ISC_R_SUCCESS) - return (result); + RETERR(result); if ((type & (DST_TYPE_PRIVATE | DST_TYPE_PUBLIC)) == DST_TYPE_PUBLIC || (pubkey->key_flags & DNS_KEYFLAG_TYPEMASK) == DNS_KEYTYPE_NOKEY) { @@ -560,7 +559,8 @@ dst_key_fromnamedfile(const char *filename, const char *dirname, isc_mem_put(mctx, newfilename, newfilenamelen); if (lex != NULL) isc_lex_destroy(&lex); - dst_key_free(&key); + if (key != NULL) + dst_key_free(&key); return (result); } diff --git a/lib/dns/name.c b/lib/dns/name.c index 97a7a6293c..0d9387f0bd 100644 --- a/lib/dns/name.c +++ b/lib/dns/name.c @@ -1429,6 +1429,7 @@ dns_name_totext2(dns_name_t *name, unsigned int options, isc_buffer_t *target) case 0x24: /* '$' */ if ((options & DNS_NAME_MASTERFILE) == 0) goto no_escape; + /* FALLTHROUGH */ case 0x22: /* '"' */ case 0x28: /* '(' */ case 0x29: /* ')' */ diff --git a/lib/dns/validator.c b/lib/dns/validator.c index 10fac204de..2c56e2db64 100644 --- a/lib/dns/validator.c +++ b/lib/dns/validator.c @@ -4235,6 +4235,8 @@ dns_validator_send(dns_validator_t *validator) { void dns_validator_cancel(dns_validator_t *validator) { + dns_fetch_t *fetch = NULL; + REQUIRE(VALID_VALIDATOR(validator)); LOCK(&validator->lock); @@ -4244,8 +4246,8 @@ dns_validator_cancel(dns_validator_t *validator) { if ((validator->attributes & VALATTR_CANCELED) == 0) { validator->attributes |= VALATTR_CANCELED; if (validator->event != NULL) { - if (validator->fetch != NULL) - dns_resolver_cancelfetch(validator->fetch); + fetch = validator->fetch; + validator->fetch = NULL; if (validator->subvalidator != NULL) dns_validator_cancel(validator->subvalidator); @@ -4256,6 +4258,10 @@ dns_validator_cancel(dns_validator_t *validator) { } } UNLOCK(&validator->lock); + + /* Need to cancel fetch outside validator lock */ + if (fetch != NULL) + dns_resolver_cancelfetch(fetch); } static void diff --git a/lib/dns/view.c b/lib/dns/view.c index 675005863e..5166ae44d1 100644 --- a/lib/dns/view.c +++ b/lib/dns/view.c @@ -482,6 +482,8 @@ view_flushanddetach(dns_view_t **viewp, isc_boolean_t flush) { view->flush = ISC_TRUE; isc_refcount_decrement(&view->references, &refs); if (refs == 0) { + dns_zone_t *mkzone = NULL; + LOCK(&view->lock); if (!RESSHUTDOWN(view)) dns_resolver_shutdown(view->resolver); @@ -497,13 +499,20 @@ view_flushanddetach(dns_view_t **viewp, isc_boolean_t flush) { else dns_zt_detach(&view->zonetable); if (view->managed_keys != NULL) { + mkzone = view->managed_keys; + view->managed_keys = NULL; if (view->flush) - dns_zone_flush(view->managed_keys); - dns_zone_detach(&view->managed_keys); + dns_zone_flush(mkzone); } #endif done = all_done(view); UNLOCK(&view->lock); + +#ifdef BIND9 + /* Need to detach zones outside view lock */ + if (mkzone != NULL) + dns_zone_detach(&mkzone); +#endif } *viewp = NULL; diff --git a/lib/dns/xfrin.c b/lib/dns/xfrin.c index eae39d9de3..589990ea8a 100644 --- a/lib/dns/xfrin.c +++ b/lib/dns/xfrin.c @@ -591,6 +591,7 @@ xfr_rr(dns_xfrin_ctx_t *xfr, dns_name_t *name, isc_uint32_t ttl, case XFRST_AXFR_END: case XFRST_IXFR_END: FAIL(DNS_R_EXTRADATA); + break; default: INSIST(0); break; diff --git a/lib/export/samples/sample-request.c b/lib/export/samples/sample-request.c index d5d2312e30..c05a861eeb 100644 --- a/lib/export/samples/sample-request.c +++ b/lib/export/samples/sample-request.c @@ -77,6 +77,9 @@ make_querymessage(dns_message_t *message, const char *namestr, isc_buffer_t b; size_t namelen; + REQUIRE(message != NULL); + REQUIRE(namestr != NULL); + /* Construct qname */ namelen = strlen(namestr); isc_buffer_init(&b, namestr, namelen); @@ -115,8 +118,7 @@ make_querymessage(dns_message_t *message, const char *namestr, dns_message_puttempname(message, &qname); if (qrdataset != NULL) dns_message_puttemprdataset(message, &qrdataset); - if (message != NULL) - dns_message_destroy(&message); + dns_message_destroy(&message); return (result); } diff --git a/lib/irs/getaddrinfo.c b/lib/irs/getaddrinfo.c index c46a40a77a..b2ed946214 100644 --- a/lib/irs/getaddrinfo.c +++ b/lib/irs/getaddrinfo.c @@ -1146,10 +1146,8 @@ add_ipv6(const char *hostname, int flags, struct addrinfo **aip, UNUSED(flags); ai = ai_clone(*aip, AF_INET6); /* don't use ai_clone() */ - if (ai == NULL) { - freeaddrinfo(*aip); + if (ai == NULL) return (EAI_MEMORY); - } *aip = ai; ai->ai_socktype = socktype; diff --git a/lib/irs/getnameinfo.c b/lib/irs/getnameinfo.c index 80e36776d1..982e8ecfdd 100644 --- a/lib/irs/getnameinfo.c +++ b/lib/irs/getnameinfo.c @@ -328,6 +328,7 @@ getnameinfo(const struct sockaddr *sa, socklen_t salen, char *host, case DNS_R_NOVALIDDS: case DNS_R_NOVALIDSIG: ERR(EAI_INSECUREDATA); + break; default: ERR(EAI_FAIL); } diff --git a/lib/irs/resconf.c b/lib/irs/resconf.c index 18525e8393..88bdac1641 100644 --- a/lib/irs/resconf.c +++ b/lib/irs/resconf.c @@ -238,7 +238,7 @@ add_server(isc_mem_t *mctx, const char *address_str, goto cleanup; } address->length = res->ai_addrlen; - memcpy(&address->type.sa, res->ai_addr, res->ai_addrlen); + memcpy(&address->type.ss, res->ai_addr, res->ai_addrlen); ISC_LINK_INIT(address, link); ISC_LIST_APPEND(*nameservers, address, link); diff --git a/lib/isc/include/isc/sockaddr.h b/lib/isc/include/isc/sockaddr.h index 1e6914222c..c774a419c4 100644 --- a/lib/isc/include/isc/sockaddr.h +++ b/lib/isc/include/isc/sockaddr.h @@ -34,6 +34,7 @@ struct isc_sockaddr { struct sockaddr sa; struct sockaddr_in sin; struct sockaddr_in6 sin6; + struct sockaddr_storage ss; #ifdef ISC_PLATFORM_HAVESYSUNH struct sockaddr_un sunix; #endif diff --git a/lib/isc/inet_aton.c b/lib/isc/inet_aton.c index 14b4887f4f..78ece5ccc0 100644 --- a/lib/isc/inet_aton.c +++ b/lib/isc/inet_aton.c @@ -91,7 +91,7 @@ static char rcsid[] = "$Id: inet_aton.c,v 1.23 2008/12/01 23:47:45 tbox Exp $"; */ int isc_net_aton(const char *cp, struct in_addr *addr) { - unsigned long val; + isc_uint32_t val; int base, n; unsigned char c; isc_uint8_t parts[4]; diff --git a/lib/isc/ratelimiter.c b/lib/isc/ratelimiter.c index 07bcc7c7af..9a819870a3 100644 --- a/lib/isc/ratelimiter.c +++ b/lib/isc/ratelimiter.c @@ -291,6 +291,7 @@ isc_ratelimiter_stall(isc_ratelimiter_t *rl) { result = isc_timer_reset(rl->timer, isc_timertype_inactive, NULL, NULL, ISC_FALSE); RUNTIME_CHECK(result == ISC_R_SUCCESS); + /* FALLTHROUGH */ case isc_ratelimiter_idle: case isc_ratelimiter_stalled: rl->state = isc_ratelimiter_stalled; diff --git a/lib/isc/sockaddr.c b/lib/isc/sockaddr.c index 7b43b8f31b..91a949b642 100644 --- a/lib/isc/sockaddr.c +++ b/lib/isc/sockaddr.c @@ -219,13 +219,12 @@ isc_sockaddr_hash(const isc_sockaddr_t *sockaddr, isc_boolean_t address_only) { break; case AF_INET6: in6 = &sockaddr->type.sin6.sin6_addr; + s = (const unsigned char *)in6; if (IN6_IS_ADDR_V4MAPPED(in6)) { - s = (const unsigned char *)&in6[12]; + s += 12; length = sizeof(sockaddr->type.sin.sin_addr.s_addr); - } else { - s = (const unsigned char *)in6; + } else length = sizeof(sockaddr->type.sin6.sin6_addr); - } p = ntohs(sockaddr->type.sin6.sin6_port); break; default: diff --git a/lib/isc/tests/Makefile.in b/lib/isc/tests/Makefile.in index 41095a1b0f..90e37dc5b6 100644 --- a/lib/isc/tests/Makefile.in +++ b/lib/isc/tests/Makefile.in @@ -36,12 +36,12 @@ LIBS = @LIBS@ @ATFLIBS@ OBJS = isctest.@O@ -SRCS = isctest.c taskpool_test.c hash_test.c symtab_test.c \ - parse_test.c +SRCS = isctest.c taskpool_test.c hash_test.c sockaddr_test.c \ + symtab_test.c parse_test.c SUBDIRS = -TARGETS = taskpool_test@EXEEXT@ hash_test@EXEEXT@ symtab_test@EXEEXT@ \ - parse_test@EXEEXT@ +TARGETS = taskpool_test@EXEEXT@ hash_test@EXEEXT@ sockaddr_test@EXEEXT@ \ + symtab_test@EXEEXT@ parse_test@EXEEXT@ @BIND9_MAKE_RULES@ @@ -61,6 +61,11 @@ parse_test@EXEEXT@: parse_test.@O@ isctest.@O@ ${ISCDEPLIBS} ${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \ parse_test.@O@ isctest.@O@ ${ISCLIBS} ${LIBS} +sockaddr_test@EXEEXT@: sockaddr_test.@O@ isctest.@O@ ${ISCDEPLIBS} + ${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \ + sockaddr_test.@O@ isctest.@O@ ${ISCLIBS} ${LIBS} + + unit:: sh ${top_srcdir}/unit/unittest.sh diff --git a/lib/isc/tests/sockaddr_test.c b/lib/isc/tests/sockaddr_test.c new file mode 100644 index 0000000000..3e3f6dde73 --- /dev/null +++ b/lib/isc/tests/sockaddr_test.c @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC") + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +/* $Id$ */ + +/*! \file */ + +#include + +#include + +#include + +#include +#include + +#include "isctest.h" + +/* + * Individual unit tests + */ + +ATF_TC(sockaddr_hash); +ATF_TC_HEAD(sockaddr_hash, tc) { + atf_tc_set_md_var(tc, "descr", "sockaddr hash"); +} +ATF_TC_BODY(sockaddr_hash, tc) { + isc_result_t result; + isc_sockaddr_t addr; + struct in_addr in; + struct in6_addr in6; + unsigned int h1, h2, h3, h4; + int ret; + + UNUSED(tc); + + result = isc_test_begin(NULL); + ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); + + in.s_addr = inet_addr("127.0.0.1"); + isc_sockaddr_fromin(&addr, &in, 1); + h1 = isc_sockaddr_hash(&addr, ISC_TRUE); + h2 = isc_sockaddr_hash(&addr, ISC_FALSE); + ATF_CHECK(h1 != h2); + + ret = inet_pton(AF_INET6, "::ffff:127.0.0.1", &in6); + ATF_CHECK(ret == 1); + isc_sockaddr_fromin6(&addr, &in6, 1); + h3 = isc_sockaddr_hash(&addr, ISC_TRUE); + h4 = isc_sockaddr_hash(&addr, ISC_FALSE); + ATF_CHECK(h1 == h3); + ATF_CHECK(h2 == h4); + + isc_test_end(); +} + +/* + * Main + */ +ATF_TP_ADD_TCS(tp) { + ATF_TP_ADD_TC(tp, sockaddr_hash); + + return (atf_no_error()); +} + diff --git a/lib/isc/timer.c b/lib/isc/timer.c index 0c80c1f980..23fcbbef64 100644 --- a/lib/isc/timer.c +++ b/lib/isc/timer.c @@ -692,7 +692,7 @@ dispatch(isc__timermgr_t *manager, isc_time_t *now) { while (manager->nscheduled > 0 && !done) { timer = isc_heap_element(manager->heap, 1); - INSIST(timer->type != isc_timertype_inactive); + INSIST(timer != NULL && timer->type != isc_timertype_inactive); if (isc_time_compare(now, &timer->due) >= 0) { if (timer->type == isc_timertype_ticker) { type = ISC_TIMEREVENT_TICK; diff --git a/lib/isc/unix/net.c b/lib/isc/unix/net.c index ea4a504ebd..1fedbc438d 100644 --- a/lib/isc/unix/net.c +++ b/lib/isc/unix/net.c @@ -301,8 +301,6 @@ try_ipv6only(void) { goto close; } - close(s); - ipv6only_result = ISC_R_SUCCESS; close: @@ -358,7 +356,6 @@ try_ipv6pktinfo(void) { goto close; } - close(s); ipv6pktinfo_result = ISC_R_SUCCESS; close: diff --git a/lib/lwres/context.c b/lib/lwres/context.c index 64bdaa107d..f8b9f8b95c 100644 --- a/lib/lwres/context.c +++ b/lib/lwres/context.c @@ -377,6 +377,7 @@ lwres_context_send(lwres_context_t *ctx, lwresult = context_connect(ctx); if (lwresult != LWRES_R_SUCCESS) return (lwresult); + INSIST(ctx->sock >= 0); } ret = sendto(ctx->sock, sendbase, sendlen, 0, NULL, 0); diff --git a/lib/lwres/getipnode.c b/lib/lwres/getipnode.c index 517f5b42f9..da00e8c871 100644 --- a/lib/lwres/getipnode.c +++ b/lib/lwres/getipnode.c @@ -955,7 +955,7 @@ copyandmerge(struct hostent *he1, struct hostent *he2, int af, int *error_num) npp = he->h_aliases; cpp = (he1 != NULL) ? he1->h_aliases : ((he2 != NULL) ? he2->h_aliases : NULL); - while (*cpp != NULL) { + while (cpp != NULL && *cpp != NULL) { len = strlen (*cpp) + 1; *npp = malloc(len); if (*npp == NULL) diff --git a/lib/lwres/lwinetaton.c b/lib/lwres/lwinetaton.c index e40c28f7ac..1d19f978bd 100644 --- a/lib/lwres/lwinetaton.c +++ b/lib/lwres/lwinetaton.c @@ -95,7 +95,7 @@ static char rcsid[] = "$Id: lwinetaton.c,v 1.16 2007/06/19 23:47:22 tbox Exp $"; */ int lwres_net_aton(const char *cp, struct in_addr *addr) { - unsigned long val; + lwres_uint32_t val; int base, n; unsigned char c; lwres_uint8_t parts[4]; diff --git a/lib/lwres/print.c b/lib/lwres/print.c index 591ed36ac3..87f30323fe 100644 --- a/lib/lwres/print.c +++ b/lib/lwres/print.c @@ -470,12 +470,16 @@ lwres__print_vsnprintf(char *str, size_t size, const char *format, va_list ap) { pad--; } break; + case 'D': /*deprecated*/ INSIST("use %ld instead of %D" == NULL); + break; case 'O': /*deprecated*/ INSIST("use %lo instead of %O" == NULL); + break; case 'U': /*deprecated*/ INSIST("use %lu instead of %U" == NULL); + break; case 'L': #ifdef HAVE_LONG_DOUBLE