From: Mark Andrews Date: Wed, 2 May 2018 03:07:28 +0000 (+1000) Subject: Silence clang static analyzer warnings; Consolidate multiple instances of splitting... X-Git-Tag: v9.13.0~24^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=92e540df1eb53ac451382752424142b56777df54;p=thirdparty%2Fbind9.git Silence clang static analyzer warnings; Consolidate multiple instances of splitting of batchline in dig into a single function. --- diff --git a/CHANGES b/CHANGES index 6b10bb78e31..bc907992a2d 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,8 @@ +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] diff --git a/bin/dig/dig.c b/bin/dig/dig.c index 197718e8a41..ee891b4e36d 100644 --- a/bin/dig/dig.c +++ b/bin/dig/dig.c @@ -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 { diff --git a/bin/tests/system/pipelined/pipequeries.c b/bin/tests/system/pipelined/pipequeries.c index 6f986c77c35..72db37c63bd 100644 --- a/bin/tests/system/pipelined/pipequeries.c +++ b/bin/tests/system/pipelined/pipequeries.c @@ -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; diff --git a/lib/dns/rbt.c b/lib/dns/rbt.c index f6551216f29..23e21dfb187 100644 --- a/lib/dns/rbt.c +++ b/lib/dns/rbt.c @@ -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(¤t_name, NULL); diff --git a/lib/ns/query.c b/lib/ns/query.c index 790840f6d18..21f1860bb61 100644 --- a/lib/ns/query.c +++ b/lib/ns/query.c @@ -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;