Commit 56f17ab3 authored by Mark Andrews's avatar Mark Andrews
Browse files

Merge branch '196-clang-scan-build-reporting-possible-null-pointer-dereferences' into 'master'

Resolve "clang scan-build reporting possible null pointer dereferences"

Closes #196

See merge request !230
parents 77023590 92e540df
Pipeline #1589 passed with stages
in 8 minutes and 6 seconds
4942. [cleanup] Consolidate multiple instances of splitting of
batchline in dig into a single function. [GL #196]
4941. [cleanup] Silence clang static analyzer warnings. [GL #196]
4940. [cleanup] Extract the loop in dns__zone_updatesigs() into
separate functions to improve code readability.
[GL #135]
......
......@@ -1856,6 +1856,22 @@ preparse_args(int argc, char **argv) {
}
}
static int
split_batchline(char *batchline, char **bargv, int len, const char *msg) {
int bargc;
char *last = NULL;
REQUIRE(batchline != NULL);
for (bargc = 1, bargv[bargc] = strtok_r(batchline, " \t\r\n", &last);
bargc < len && bargv[bargc];
bargv[++bargc] = strtok_r(NULL, " \t\r\n", &last))
{
debug("%s %d: %s", msg, bargc, bargv[bargc]);
}
return (bargc);
}
static void
parse_args(isc_boolean_t is_batchfile, isc_boolean_t config_only,
int argc, char **argv)
......@@ -1876,7 +1892,6 @@ parse_args(isc_boolean_t is_batchfile, isc_boolean_t config_only,
char *homedir;
char rcfile[PATH_MAX];
#endif
char *last;
isc_boolean_t need_clone = ISC_TRUE;
/*
......@@ -1906,23 +1921,23 @@ parse_args(isc_boolean_t is_batchfile, isc_boolean_t config_only,
homedir = getenv("HOME");
if (homedir != NULL) {
unsigned int n;
n = snprintf(rcfile, sizeof(rcfile), "%s/.digrc", homedir);
n = snprintf(rcfile, sizeof(rcfile), "%s/.digrc",
homedir);
if (n < sizeof(rcfile)) {
batchfp = fopen(rcfile, "r");
}
}
if (batchfp != NULL) {
while (fgets(batchline, sizeof(batchline), batchfp) != 0) {
while (fgets(batchline, sizeof(batchline),
batchfp) != 0)
{
debug("config line %s", batchline);
for (bargc = 1, bargv[bargc] = strtok_r(batchline, " \t\r\n", &last);
bargc < 62 && bargv[bargc];
bargv[++bargc] = strtok_r(NULL, " \t\r\n", &last))
{
debug(".digrc argv %d: %s", bargc, bargv[bargc]);
}
bargc = split_batchline(batchline, bargv, 62,
".digrc argv");
bargv[0] = argv[0];
argv0 = argv[0];
parse_args(ISC_TRUE, ISC_TRUE, bargc, (char **)bargv);
parse_args(ISC_TRUE, ISC_TRUE,
bargc, (char **)bargv);
}
fclose(batchfp);
}
......@@ -2102,20 +2117,14 @@ parse_args(isc_boolean_t is_batchfile, isc_boolean_t config_only,
/* XXX Remove code dup from shutdown code */
next_line:
if (fgets(batchline, sizeof(batchline), batchfp) != 0) {
bargc = 1;
debug("batch line %s", batchline);
if (batchline[0] == '\r' || batchline[0] == '\n'
|| batchline[0] == '#' || batchline[0] == ';')
if (batchline[0] == '\r' || batchline[0] == '\n' ||
batchline[0] == '#' || batchline[0] == ';')
goto next_line;
for (bargc = 1, bargv[bargc] = strtok_r(batchline, " \t\r\n", &last);
(bargc < 14) && bargv[bargc];
bargc++, bargv[bargc] = strtok_r(NULL, " \t\r\n", &last)) {
debug("batch argv %d: %s", bargc, bargv[bargc]);
}
bargc = split_batchline(batchline, bargv, 14,
"batch argv");
bargv[0] = argv[0];
argv0 = argv[0];
parse_args(ISC_TRUE, ISC_FALSE, bargc, (char **)bargv);
return;
}
......@@ -2154,7 +2163,6 @@ query_finished(void) {
char batchline[MXNAME];
int bargc;
char *bargv[16];
char *last;
if (batchname == NULL) {
isc_app_shutdown();
......@@ -2172,15 +2180,8 @@ query_finished(void) {
if (fgets(batchline, sizeof(batchline), batchfp) != 0) {
debug("batch line %s", batchline);
for (bargc = 1, bargv[bargc] = strtok_r(batchline, " \t\r\n", &last);
bargc < 14 && bargv[bargc];
bargc++, bargv[bargc] = strtok_r(NULL, " \t\r\n", &last))
{
debug("batch argv %d: %s", bargc, bargv[bargc]);
}
bargc = split_batchline(batchline, bargv, 14, "batch argv");
bargv[0] = argv0;
parse_args(ISC_TRUE, ISC_FALSE, bargc, (char **)bargv);
start_lookup();
} else {
......
......@@ -250,6 +250,7 @@ main(int argc, char *argv[]) {
argc -= isc_commandline_index;
argv += isc_commandline_index;
POST(argv);
if (argc > 0) {
have_src = ISC_TRUE;
......
......@@ -1191,6 +1191,7 @@ dns_rbt_addnode(dns_rbt_t *rbt, const dns_name_t *name, dns_rbtnode_t **nodep) {
* not modified.
*/
add_name = dns_fixedname_initname(&fixedcopy);
INSIST(add_name != NULL);
dns_name_clone(name, add_name);
if (ISC_UNLIKELY(rbt->root == NULL)) {
......@@ -1213,6 +1214,9 @@ dns_rbt_addnode(dns_rbt_t *rbt, const dns_name_t *name, dns_rbtnode_t **nodep) {
prefix = dns_fixedname_initname(&fixedprefix);
suffix = dns_fixedname_initname(&fixedsuffix);
INSIST(prefix != NULL);
INSIST(suffix != NULL);
root = &rbt->root;
INSIST(IS_ROOT(*root));
parent = NULL;
......@@ -1534,6 +1538,7 @@ dns_rbt_findnode(dns_rbt_t *rbt, const dns_name_t *name, dns_name_t *foundname,
* the lack of bitstring labels.
*/
search_name = dns_fixedname_initname(&fixedsearchname);
INSIST(search_name != NULL);
dns_name_clone(name, search_name);
dns_name_init(&current_name, NULL);
......
......@@ -2107,6 +2107,8 @@ query_addrrset(ns_client_t *client, dns_name_t **namep,
CTRACE(ISC_LOG_DEBUG(3), "query_addrrset");
REQUIRE(name != NULL);
if (sigrdatasetp != NULL)
sigrdataset = *sigrdatasetp;
......
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