Commit 47c5b8af authored by Evan Hunt's avatar Evan Hunt

[master] silence coverity warnings

3401.	[bug]		Addressed Coverity warnings. [RT #31484]
parent 3b9b4c75
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]
......
......@@ -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();
......
......@@ -395,6 +395,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();
......
......@@ -1467,9 +1467,9 @@ client_request(isc_task_t *task, isc_event_t *event) {
INSIST(client->recursionquota == NULL);
INSIST(client->state == TCP_CLIENT(client) ?
INSIST(client->state == (TCP_CLIENT(client) ?
NS_CLIENTSTATE_READING :
NS_CLIENTSTATE_READY);
NS_CLIENTSTATE_READY));
ns_client_requests++;
......@@ -2655,7 +2655,9 @@ get_client(ns_clientmgr_t *manager, ns_interface_t *ifp,
ns_client_t *client;
MTRACE("get client");
if (manager != NULL && manager->exiting)
REQUIRE(manager != NULL);
if (manager->exiting)
return (ISC_R_SHUTTINGDOWN);
/*
......
......@@ -8284,8 +8284,6 @@ ns_server_zonestatus(ns_server_t *server, char *args, isc_buffer_t *text) {
isc_time_settoepoch(&resigntime);
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;
......
......@@ -795,6 +795,7 @@ main(int argc, char **argv) {
program, isc_commandline_option);
usage(1);
}
/* FALLTHROUGH */
case 'h':
usage(0);
break;
......
......@@ -612,24 +612,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;
......@@ -703,10 +705,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;
}
......@@ -714,14 +724,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;
}
......
......@@ -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;
......
......@@ -123,7 +123,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);
}
......@@ -307,7 +307,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;
isc_sockaddr_t *src;
char full_name[100];
char full_name[256];
int i;
UNUSED(zone);
......@@ -315,10 +315,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);
if (strcmp(name, "source-addr") == 0) {
char buf[100];
......
......@@ -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();
......
......@@ -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);
......@@ -844,7 +846,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);
......
......@@ -2104,6 +2104,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)
......@@ -2134,6 +2135,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)
......
......@@ -2980,8 +2980,6 @@ get_udpsocket(dns_dispatchmgr_t *mgr, dns_dispatch_t *disp,
result = open_socket(sockmgr, localaddr, 0, &sock, NULL);
if (result != ISC_R_SUCCESS)
goto end;
else if (!anyport)
break;
else if (portavailable(mgr, sock, NULL))
break;
if (held[i] != NULL)
......@@ -3783,7 +3781,7 @@ dns_dispatchset_create(isc_mem_t *mctx, isc_socketmgr_t *sockmgr,
goto fail_alloc;
dset->dispatches = isc_mem_get(mctx, sizeof(dns_dispatch_t *) * n);
if (dset == NULL) {
if (dset->dispatches == NULL) {
result = ISC_R_NOMEMORY;
goto fail_lock;
}
......
......@@ -531,8 +531,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) {
......@@ -596,7 +595,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);
}
......
......@@ -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: /* ')' */
......
......@@ -393,6 +393,7 @@ static isc_result_t
write_header(FILE *file, dns_rbt_t *rbt, isc_uint64_t first_node_offset) {
file_header_t header;
isc_result_t result;
long location;
if (FILE_VERSION[0] == '\0') {
memset(FILE_VERSION, 0, sizeof(FILE_VERSION));
......@@ -415,8 +416,11 @@ write_header(FILE *file, dns_rbt_t *rbt, isc_uint64_t first_node_offset) {
header.nodecount = rbt->nodecount;
CHECK(isc_stdio_seek(file, dns_rbt_serialize_align(ftell(file)),
SEEK_SET));
location = ftell(file);
if (location < 0)
return (ISC_R_FAILURE);
location = dns_rbt_serialize_align(location);
CHECK(isc_stdio_seek(file, location, SEEK_SET));
CHECK(isc_stdio_write(&header, 1, sizeof(file_header_t), file, NULL));
CHECK(fflush(file));
......@@ -441,6 +445,9 @@ serialize_node(FILE *file, dns_rbtnode_t *node, uintptr_t left,
INSIST(node != NULL);
file_position = ftell(file);
if (file_position < 0)
return (ISC_R_FAILURE);
file_position = dns_rbt_serialize_align(file_position);
CHECK(isc_stdio_seek(file, file_position, SEEK_SET));
......@@ -497,7 +504,7 @@ serialize_nodes(FILE *file, dns_rbtnode_t *node, uintptr_t parent,
uintptr_t *where)
{
uintptr_t left = 0, right = 0, down = 0, data = 0;
long this_node_location = 0;
long location = 0;
isc_uint64_t offset_adjust;
isc_result_t result;
......@@ -508,30 +515,46 @@ serialize_nodes(FILE *file, dns_rbtnode_t *node, uintptr_t parent,
}
/* Reserve space for current node */
CHECK(isc_stdio_seek(file, dns_rbt_serialize_align(ftell(file)),
SEEK_SET));
this_node_location = ftell(file);
offset_adjust = dns_rbt_serialize_align(this_node_location +
NODE_SIZE(node));
location = ftell(file);
if (location < 0)
return (ISC_R_FAILURE);
location = dns_rbt_serialize_align(location);
CHECK(isc_stdio_seek(file, location, SEEK_SET));
location = ftell(file);
if (location < 0)
return (ISC_R_FAILURE);
offset_adjust = dns_rbt_serialize_align(location + NODE_SIZE(node));
CHECK(isc_stdio_seek(file, offset_adjust, SEEK_SET));
/* Serialize the rest of the tree */
CHECK(serialize_nodes(file, getleft(node, NULL), this_node_location,
CHECK(serialize_nodes(file, getleft(node, NULL), location,
datawriter, serial, &left));
CHECK(serialize_nodes(file, getright(node, NULL), this_node_location,
CHECK(serialize_nodes(file, getright(node, NULL), location,
datawriter, serial, &right));
CHECK(serialize_nodes(file, getdown(node, NULL), this_node_location,
CHECK(serialize_nodes(file, getdown(node, NULL), location,
datawriter, serial, &down));
if (node->data != NULL) {
CHECK(isc_stdio_seek(file, dns_rbt_serialize_align(ftell(file)),
SEEK_SET));
data = ftell(file);
long ret;
ret = ftell(file);
if (ret < 0)
return (ISC_R_FAILURE);
ret = dns_rbt_serialize_align(ret);
CHECK(isc_stdio_seek(file, ret, SEEK_SET));
ret = ftell(file);
if (ret < 0)
return (ISC_R_FAILURE);
data = ret;
datawriter(file, node->data, serial);
}
/* Seek back to reserved space */
CHECK(isc_stdio_seek(file, this_node_location, SEEK_SET));
CHECK(isc_stdio_seek(file, location, SEEK_SET));
/* Serialize the current node */
CHECK(serialize_node(file, node, left, right, down, parent, data));
......@@ -540,7 +563,7 @@ serialize_nodes(FILE *file, dns_rbtnode_t *node, uintptr_t parent,
CHECK(isc_stdio_seek(file, 0, SEEK_END));
if (where != NULL)
*where = this_node_location;
*where = location;
cleanup:
return (result);
......@@ -569,14 +592,21 @@ dns_rbt_serialize_tree(FILE *file, dns_rbt_t *rbt,
CHECK(isc_file_isplainfilefd(fileno(file)));
header_position = ftell(file);
if (header_position < 0)
return (ISC_R_FAILURE);
/* Write dummy header */
CHECK(dns_rbt_zero_header(file));
/* Serialize nodes */
node_position = ftell(file);
if (node_position < 0)
return (ISC_R_FAILURE);
CHECK(serialize_nodes(file, rbt->root, 0, datawriter, serial, NULL));
end_position = ftell(file);
if (end_position < 0)
return (ISC_R_FAILURE);
if (node_position == end_position) {
CHECK(isc_stdio_seek(file, header_position, SEEK_SET));
......
......@@ -7448,7 +7448,7 @@ serialize(dns_db_t *db, dns_dbversion_t *ver, FILE *rbtfile) {
long tree_location;
long nsec_location;
long nsec3_location;
long rbtdb_header_location;
long header_location;
rbtdb = (dns_rbtdb_t *)db;
......@@ -7470,7 +7470,10 @@ serialize(dns_db_t *db, dns_dbversion_t *ver, FILE *rbtfile) {
* NOTE: need to do something better with the return codes, &= will
* not work.
*/
rbtdb_header_location = ftell(rbtfile);
header_location = ftell(rbtfile);
if (header_location < 0)
return (ISC_R_FAILURE);
CHECK(rbtdb_zero_header(rbtfile));
CHECK(dns_rbt_serialize_tree(rbtfile, rbtdb->tree, rbt_datawriter,
version->serial,
......@@ -7482,9 +7485,7 @@ serialize(dns_db_t *db, dns_dbversion_t *ver, FILE *rbtfile) {
version->serial,
&nsec3_location));
result = isc_stdio_seek(rbtfile, rbtdb_header_location, SEEK_SET);
if (result != ISC_R_SUCCESS)
return (result);
CHECK(isc_stdio_seek(rbtfile, header_location, SEEK_SET));
CHECK(rbtdb_write_header(rbtfile, tree_location, nsec_location,
nsec3_location));
failure:
......
......@@ -4233,6 +4233,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);
......@@ -4242,8 +4244,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);
......@@ -4254,6 +4256,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
......
......@@ -490,6 +490,8 @@ view_flushanddetach(dns_view_t **viewp, isc_boolean_t flush) {
view->flush = ISC_TRUE;