Commit 41bbb34b authored by Evan Hunt's avatar Evan Hunt
Browse files

fix coverity issues

3388.	[bug]		Fixed several Coverity warnings. [RT #30996]
parent 02bbbc26
3388. [bug] Fixed several Coverity warnings. [RT #30996]
3387. [func] DS digest can be disabled at runtime with
disable-ds-digests. [RT #21581]
......
......@@ -196,6 +196,10 @@ checkns(dns_zone_t *zone, dns_name_t *name, dns_name_t *owner,
a->type == dns_rdatatype_a);
REQUIRE(aaaa == NULL || !dns_rdataset_isassociated(aaaa) ||
aaaa->type == dns_rdatatype_aaaa);
if (a == NULL || aaaa == NULL)
return (answer);
memset(&hints, 0, sizeof(hints));
hints.ai_flags = AI_CANONNAME;
hints.ai_family = PF_UNSPEC;
......@@ -258,8 +262,7 @@ checkns(dns_zone_t *zone, dns_name_t *name, dns_name_t *owner,
}
return (ISC_TRUE);
}
if (a == NULL || aaaa == NULL)
return (answer);
/*
* Check that all glue records really exist.
*/
......
......@@ -812,11 +812,11 @@ clone_lookup(dig_lookup_t *lookold, isc_boolean_t servers) {
looknew = make_empty_lookup();
INSIST(looknew != NULL);
strncpy(looknew->textname, lookold->textname, MXNAME);
strlcpy(looknew->textname, lookold->textname, MXNAME);
#if DIG_SIGCHASE_TD
strncpy(looknew->textnamesigchase, lookold->textnamesigchase, MXNAME);
strlcpy(looknew->textnamesigchase, lookold->textnamesigchase, MXNAME);
#endif
strncpy(looknew->cmdline, lookold->cmdline, MXNAME);
strlcpy(looknew->cmdline, lookold->cmdline, MXNAME);
looknew->textname[MXNAME-1] = 0;
looknew->rdtype = lookold->rdtype;
looknew->qrdtype = lookold->qrdtype;
......@@ -993,7 +993,7 @@ parse_hmac(const char *hmac) {
len = strlen(hmac);
if (len >= (int) sizeof(buf))
fatal("unknown key type '%.*s'", len, hmac);
strncpy(buf, hmac, sizeof(buf));
strlcpy(buf, hmac, sizeof(buf));
digestbits = 0;
......@@ -1075,8 +1075,8 @@ read_confkey(void) {
secretstr = cfg_obj_asstring(secretobj);
algorithm = cfg_obj_asstring(algorithmobj);
strncpy(keynametext, keyname, sizeof(keynametext));
strncpy(keysecret, secretstr, sizeof(keysecret));
strlcpy(keynametext, keyname, sizeof(keynametext));
strlcpy(keysecret, secretstr, sizeof(keysecret));
parse_hmac(algorithm);
setup_text_key();
......@@ -1159,7 +1159,7 @@ make_searchlist_entry(char *domain) {
if (search == NULL)
fatal("memory allocation failure in %s:%d",
__FILE__, __LINE__);
strncpy(search->origin, domain, MXNAME);
strlcpy(search->origin, domain, MXNAME);
search->origin[MXNAME-1] = 0;
ISC_LINK_INIT(search, link);
return (search);
......@@ -1637,7 +1637,7 @@ start_lookup(void) {
= current_lookup->rdclassset;
current_lookup->rdclass = dns_rdataclass_in;
strncpy(current_lookup->textnamesigchase,
strlcpy(current_lookup->textnamesigchase,
current_lookup->textname, MXNAME);
current_lookup->trace_root_sigchase = ISC_TRUE;
......@@ -1649,7 +1649,7 @@ start_lookup(void) {
check_result(result, "dns_name_totext");
isc_buffer_usedregion(b, &r);
r.base[r.length] = '\0';
strncpy(current_lookup->textname, (char*)r.base,
strlcpy(current_lookup->textname, (char*)r.base,
MXNAME);
isc_buffer_free(&b);
......@@ -4079,7 +4079,7 @@ sigchase_scanname(dns_rdatatype_t type, dns_rdatatype_t covers,
check_result(result, "dns_name_totext");
isc_buffer_usedregion(b, &r);
r.base[r.length] = '\0';
strcpy(lookup->textname, (char*)r.base);
strlcpy(lookup->textname, (char*)r.base, sizeof(lookup->textname));
isc_buffer_free(&b);
if (type == dns_rdatatype_rrsig)
......@@ -4204,7 +4204,7 @@ opentmpkey(isc_mem_t *mctx, const char *file, char **tempp, FILE **fp) {
return (ISC_R_NOMEMORY);
memset(tempnamekey, 0, tempnamekeylen);
strncpy(tempnamekey, tempname, tempnamelen);
strlcpy(tempnamekey, tempname, tempnamelen);
strcat(tempnamekey ,".key");
......@@ -4338,7 +4338,7 @@ prepare_lookup(dns_name_t *name)
lookup->new_search = ISC_TRUE;
lookup->trace_root_sigchase = ISC_FALSE;
strncpy(lookup->textname, lookup->textnamesigchase, MXNAME);
strlcpy(lookup->textname, lookup->textnamesigchase, MXNAME);
lookup->rdtype = lookup->rdtype_sigchase;
lookup->rdtypeset = ISC_TRUE;
......@@ -4397,7 +4397,7 @@ prepare_lookup(dns_name_t *name)
dns_rdata_totext(&aaaa, &ns.name, b);
isc_buffer_usedregion(b, &r);
r.base[r.length] = '\0';
strncpy(namestr, (char*)r.base,
strlcpy(namestr, (char*)r.base,
DNS_NAME_FORMATSIZE);
isc_buffer_free(&b);
dns_rdata_reset(&aaaa);
......@@ -4426,7 +4426,7 @@ prepare_lookup(dns_name_t *name)
dns_rdata_totext(&a, &ns.name, b);
isc_buffer_usedregion(b, &r);
r.base[r.length] = '\0';
strncpy(namestr, (char*)r.base,
strlcpy(namestr, (char*)r.base,
DNS_NAME_FORMATSIZE);
isc_buffer_free(&b);
dns_rdata_reset(&a);
......@@ -4605,7 +4605,6 @@ contains_trusted_key(dns_name_t *name, dns_rdataset_t *rdataset,
{
isc_result_t result;
dns_rdata_t rdata = DNS_RDATA_INIT;
dst_key_t *trustedKey = NULL;
dst_key_t *dnsseckey = NULL;
int i;
......@@ -4649,10 +4648,6 @@ contains_trusted_key(dns_name_t *name, dns_rdataset_t *rdataset,
dst_key_free(&dnsseckey);
} while (dns_rdataset_next(rdataset) == ISC_R_SUCCESS);
if (trustedKey != NULL)
dst_key_free(&trustedKey);
trustedKey = NULL;
return (ISC_R_NOTFOUND);
}
......
......@@ -2590,7 +2590,7 @@ set_nsec3params(isc_boolean_t update_chain, isc_boolean_t set_salt,
dns_rdata_nsec3_t nsec3;
dns_fixedname_t fname;
dns_name_t *hashname;
unsigned char orig_salt[256];
unsigned char orig_salt[255];
size_t orig_saltlen;
dns_hash_t orig_hash;
isc_uint16_t orig_iter;
......
......@@ -5297,10 +5297,12 @@ dns64_ttl(dns_db_t *db, dns_dbversion_t *version) {
isc_result_t result;
isc_uint32_t ttl = ISC_UINT32_MAX;
dns_rdataset_init(&rdataset);
result = dns_db_getoriginnode(db, &node);
if (result != ISC_R_SUCCESS)
goto cleanup;
dns_rdataset_init(&rdataset);
result = dns_db_findrdataset(db, node, version, dns_rdatatype_soa,
0, 0, &rdataset, NULL);
if (result != ISC_R_SUCCESS)
......
......@@ -7871,8 +7871,7 @@ ns_server_del_zone(ns_server_t *server, char *args) {
/* Parse parameters */
CHECK(zone_from_args(server, args, NULL, &zone, &zonename, ISC_TRUE));
if (result != ISC_R_SUCCESS)
return (result);
if (zone == NULL) {
result = ISC_R_UNEXPECTEDEND;
goto cleanup;
......
......@@ -228,7 +228,9 @@ dlopen_dlz_create(const char *dlzname, unsigned int argc, char *argv[],
return (ISC_R_FAILURE);
}
isc_mem_create(0, 0, &mctx);
result = isc_mem_create(0, 0, &mctx);
if (result != ISC_R_SUCCESS)
return (result);
cd = isc_mem_get(mctx, sizeof(*cd));
if (cd == NULL) {
......
......@@ -936,7 +936,7 @@ ns_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
INSIST(0);
}
if (raw != NULL) {
if (raw != NULL && filename != NULL) {
#define SIGNED ".signed"
size_t signedlen = strlen(filename) + sizeof(SIGNED);
char *signedname;
......
......@@ -407,12 +407,20 @@ process_dir(isc_dir_t dir, void *passback, config_data_t *cd,
*/
while ((tmpPtr = strrchr(tmpString,
cd->pathsep))
!= NULL) {
!= NULL)
{
if ((strlen(host) +
strlen(tmpPtr + 1) + 2)
> ISC_DIR_NAMEMAX)
continue;
strcat(host, tmpPtr + 1);
strcat(host, ".");
tmpPtr[0] = '\0';
}
strcat(host, tmpString);
if ((strlen(host) +
strlen(tmpString) + 1)
<= ISC_DIR_NAMEMAX)
strcat(host, tmpString);
}
foundHost = ISC_TRUE;
......
......@@ -439,18 +439,17 @@ ldap_process_results(LDAP *dbc, LDAPMessage *msg, char ** attrs,
break;
case 2:
j++;
if (allnodes == isc_boolean_true) {
if (allnodes)
host = isc_mem_strdup(ns_g_mctx,
vals[0]);
} else {
else
strcpy(data, vals[0]);
}
break;
case 3:
j++;
if (allnodes == isc_boolean_true) {
if (allnodes)
strcpy(data, vals[0]);
} else {
else {
strcat(data, " ");
strcat(data, vals[0]);
}
......@@ -487,7 +486,7 @@ ldap_process_results(LDAP *dbc, LDAPMessage *msg, char ** attrs,
goto cleanup;
}
if (allnodes == isc_boolean_true) {
if (allnodes && host != NULL) {
if (strcasecmp(host, "~") == 0)
result = dns_sdlz_putnamedrr(
(dns_sdlzallnodes_t *) ptr,
......
......@@ -963,7 +963,8 @@ mysql_create(const char *dlzname, unsigned int argc, char *argv[],
full_cleanup:
destroy_sqldbinstance(dbi);
if (dbi != NULL)
destroy_sqldbinstance(dbi);
cleanup:
......
......@@ -2891,9 +2891,10 @@ dns_dispatch_getudp(dns_dispatchmgr_t *mgr, isc_socketmgr_t *sockmgr,
unsigned int attributes, unsigned int mask,
dns_dispatch_t **dispp)
{
return dns_dispatch_getudp_dup(mgr, sockmgr, taskmgr, localaddr,
buffersize, maxbuffers, maxrequests, buckets, increment,
attributes, mask, dispp, NULL);
return (dns_dispatch_getudp_dup(mgr, sockmgr, taskmgr, localaddr,
buffersize, maxbuffers, maxrequests,
buckets, increment, attributes,
mask, dispp, NULL));
}
/*
......
......@@ -340,10 +340,10 @@ insert_into_typenames(int type, const char *typename, const char *attr) {
typename);
exit(1);
}
strcpy(ttn->typename, typename);
strncpy(ttn->typename, typename, TYPECLASSLEN);
ttn->type = type;
strcpy(ttn->macroname, ttn->typename);
strncpy(ttn->macroname, ttn->typename, TYPECLASSLEN);
c = strlen(ttn->macroname);
while (c > 0) {
if (ttn->macroname[c - 1] == '-')
......@@ -352,7 +352,8 @@ insert_into_typenames(int type, const char *typename, const char *attr) {
}
if (attr == NULL) {
sprintf(tmp, "RRTYPE_%s_ATTRIBUTES", upper(ttn->macroname));
snprintf(tmp, sizeof(tmp),
"RRTYPE_%s_ATTRIBUTES", upper(ttn->macroname));
attr = tmp;
}
......@@ -367,7 +368,7 @@ insert_into_typenames(int type, const char *typename, const char *attr) {
attr, typename);
exit(1);
}
strcpy(ttn->attr, attr);
strncpy(ttn->attr, attr, sizeof(ttn->attr));
ttn->sorted = 0;
if (maxtype < type)
maxtype = type;
......@@ -392,11 +393,11 @@ add(int rdclass, const char *classname, int type, const char *typename,
newtt->next = NULL;
newtt->rdclass = rdclass;
newtt->type = type;
strcpy(newtt->classname, classname);
strcpy(newtt->typename, typename);
strncpy(newtt->classname, classname, TYPECLASSLEN);
strncpy(newtt->typename, typename, TYPECLASSLEN);
if (strncmp(dirname, "./", 2) == 0)
dirname += 2;
strcpy(newtt->dirname, dirname);
strncpy(newtt->dirname, dirname, 256);
tt = types;
oldtt = NULL;
......@@ -430,7 +431,7 @@ add(int rdclass, const char *classname, int type, const char *typename,
newcc = (struct cc *)malloc(sizeof(*newcc));
newcc->rdclass = rdclass;
strcpy(newcc->classname, classname);
strncpy(newcc->classname, classname, TYPECLASSLEN);
cc = classes;
oldcc = NULL;
......@@ -462,14 +463,15 @@ sd(int rdclass, const char *classname, const char *dirname, char filetype) {
if (!start_directory(dirname, &dir))
return;
sprintf(fmt,"%s%c", "%20[-0-9a-z]_%d.", filetype);
snprintf(fmt, sizeof(fmt), "%s%c", "%20[-0-9a-z]_%d.", filetype);
while (next_file(&dir)) {
if (sscanf(dir.filename, fmt, typename, &type) != 2)
continue;
if ((type > 65535) || (type < 0))
continue;
sprintf(buf, "%s_%d.%c", typename, type, filetype);
snprintf(buf, sizeof(buf),
"%s_%d.%c", typename, type, filetype);
if (strcmp(buf, dir.filename) != 0)
continue;
add(rdclass, classname, type, typename, dirname);
......@@ -561,7 +563,8 @@ main(int argc, char **argv) {
filetype = 'h';
break;
case 's':
sprintf(srcdir, "%s/", isc_commandline_argument);
snprintf(srcdir, sizeof(srcdir),
"%s/", isc_commandline_argument);
break;
case 'F':
file = isc_commandline_argument;
......@@ -576,7 +579,7 @@ main(int argc, char **argv) {
exit(1);
}
sprintf(buf, "%srdata", srcdir);
snprintf(buf, sizeof(buf), "%srdata", srcdir);
if (!start_directory(buf, &dir))
exit(1);
......@@ -588,18 +591,19 @@ main(int argc, char **argv) {
if ((rdclass > 65535) || (rdclass < 0))
continue;
sprintf(buf, "%srdata/%s_%d", srcdir, classname, rdclass);
snprintf(buf, sizeof(buf),
"%srdata/%s_%d", srcdir, classname, rdclass);
if (strcmp(buf + 6 + strlen(srcdir), dir.filename) != 0)
continue;
sd(rdclass, classname, buf, filetype);
}
end_directory(&dir);
sprintf(buf, "%srdata/generic", srcdir);
snprintf(buf, sizeof(buf), "%srdata/generic", srcdir);
sd(0, "", buf, filetype);
if (time(&now) != -1) {
if ((tm = localtime(&now)) != NULL && tm->tm_year > 104)
sprintf(year, "-%d", tm->tm_year + 1900);
snprintf(year, sizeof(year), "-%d", tm->tm_year + 1900);
else
year[0] = 0;
} else
......@@ -862,7 +866,7 @@ main(int argc, char **argv) {
}
}
for (tt = types; tt != NULL; tt = tt->next) {
sprintf(buf, "%s/%s_%d.h",
snprintf(buf, sizeof(buf), "%s/%s_%d.h",
tt->dirname, tt->typename, tt->type);
if ((fd = fopen(buf,"r")) != NULL) {
while (fgets(buf, sizeof(buf), fd) != NULL)
......
......@@ -2491,7 +2491,7 @@ findname(fetchctx_t *fctx, dns_name_t *name, in_port_t port,
isc_result_t result;
res = fctx->res;
unshared = ISC_TF((fctx->options | DNS_FETCHOPT_UNSHARED) != 0);
unshared = ISC_TF((fctx->options & DNS_FETCHOPT_UNSHARED) != 0);
/*
* If this name is a subdomain of the query domain, tell
* the ADB to start looking using zone/hint data. This keeps us
......
......@@ -508,7 +508,7 @@ ip2name(dns_rpz_cidr_t *cidr, const dns_rpz_cidr_key_t *tgt_ip,
while (i < DNS_RPZ_CIDR_WORDS * 2 && w[i] == 0)
++i;
}
if (len > (int)sizeof(str))
if (len >= (int)sizeof(str))
return (ISC_R_FAILURE);
}
}
......
......@@ -79,7 +79,7 @@ ux_socket_connect(const char *path) {
memset(&addr, 0, sizeof(addr));
addr.sun_family = AF_UNIX;
strncpy(addr.sun_path, path, sizeof(addr.sun_path));
strlcpy(addr.sun_path, path, sizeof(addr.sun_path));
fd = socket(AF_UNIX, SOCK_STREAM, 0);
if (fd == -1) {
......
......@@ -2970,16 +2970,17 @@ findnsec3proofs(dns_validator_t *val) {
setclosest = setnearest = ISC_FALSE;
optout = ISC_FALSE;
unknown = ISC_FALSE;
(void)nsec3noexistnodata(val, val->event->name, name, rdataset,
zonename, &exists, &data, &optout,
&unknown, setclosestp, &setnearest,
closestp, nearest);
if (setclosest)
proofs[DNS_VALIDATOR_CLOSESTENCLOSER] = name;
result = nsec3noexistnodata(val, val->event->name, name,
rdataset, zonename, &exists,
&data, &optout, &unknown,
setclosestp, &setnearest,
closestp, nearest);
if (unknown)
val->attributes |= VALATTR_FOUNDUNKNOWN;
if (result != ISC_R_SUCCESS)
continue;
if (setclosest)
proofs[DNS_VALIDATOR_CLOSESTENCLOSER] = name;
if (exists && !data && NEEDNODATA(val)) {
val->attributes |= VALATTR_FOUNDNODATA;
proofs[DNS_VALIDATOR_NODATAPROOF] = name;
......
......@@ -12418,7 +12418,6 @@ receive_secure_serial(isc_task_t *task, isc_event_t *event) {
isc_uint32_t start, end;
dns_zone_t *zone;
dns_db_t *db = NULL;
dns_dbnode_t *node = NULL;
dns_dbversion_t *newver = NULL, *oldver = NULL;
dns_diff_t diff;
dns_difftuple_t *tuple = NULL, *soatuple = NULL;
......@@ -12559,8 +12558,6 @@ receive_secure_serial(isc_task_t *task, isc_event_t *event) {
dns_db_closeversion(db, &oldver, ISC_FALSE);
if (newver != NULL)
dns_db_closeversion(db, &newver, ISC_FALSE);
if (node != NULL)
dns_db_detachnode(db, &node);
dns_db_detach(&db);
}
if (rjournal != NULL)
......
......@@ -61,7 +61,7 @@ do_gai(int family, char *hostname) {
}
}
freeaddrinfo(res);
freeaddrinfo(res0);
}
int
......
......@@ -372,7 +372,7 @@ parse_name(char **cmdlinep, dns_name_t *name) {
isc_buffer_t source;
word = nsu_strsep(cmdlinep, " \t\r\n");
if (*word == 0) {
if (word == NULL || *word == 0) {
fprintf(stderr, "could not read owner name\n");
exit(1);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment