]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
4775. [bug] Address Coverity warnings in ht_test.c and mem_test.c
authorMark Andrews <marka@isc.org>
Thu, 19 Oct 2017 02:08:31 +0000 (13:08 +1100)
committerMark Andrews <marka@isc.org>
Thu, 19 Oct 2017 02:08:31 +0000 (13:08 +1100)
                        [RT #46281]

CHANGES
lib/isc/tests/ht_test.c
lib/isc/tests/mem_test.c

diff --git a/CHANGES b/CHANGES
index 8c3fd4ede6db976045cd0be8bd3ba1c4a058d8ac..b8019bbda787c4c6443d52f5440551feb9df1b9b 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,6 @@
+4775.  [bug]           Address Coverity warnings in ht_test.c and mem_test.c
+                       [RT #46281]
+
 4774.  [bug]           <isc/util.h> was incorrectly included in several
                        header files. [RT #46311]
 
index 7807e7a41f6f278f5098a127e9aedd0ff531bf07..ee0b41d375fb1632433db196be0701436af189e1 100644 (file)
@@ -48,7 +48,10 @@ static void test_ht_full(int bits, int count) {
                                  NULL, &mctx, 0);
        ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
 
-       isc_ht_init(&ht, mctx, bits);
+       result = isc_ht_init(&ht, mctx, bits);
+       ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
+       ATF_REQUIRE(ht != NULL);
+
        for (i = 1; i < count; i++) {
                /*
                 * Note: snprintf() is followed with strlcat()
index 3cb67c6101d7e5259ffd036d44ebdfb9acb80df1..0184d685768aae2661cbb12ed2d4d33a9b396d49 100644 (file)
@@ -155,7 +155,6 @@ ATF_TC_BODY(isc_mem_noflags, tc) {
        char buf[4096], *p, *q;
        FILE *f;
        void *ptr;
-       size_t size;
 
        result = isc_stdio_open("mem.output", "w", &f);
        ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
@@ -174,22 +173,27 @@ ATF_TC_BODY(isc_mem_noflags, tc) {
        isc_mem_destroy(&mctx2);
        isc_stdio_close(f);
 
+       memset(buf, 0, sizeof(buf));
        result = isc_stdio_open("mem.output", "r", &f);
        ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
-       result = isc_stdio_read(buf, sizeof(buf), 1, f, &size);
+       result = isc_stdio_read(buf, sizeof(buf), 1, f, NULL);
        ATF_REQUIRE_EQ(result, ISC_R_EOF);
        isc_stdio_close(f);
        isc_file_remove("mem.output");
 
+       buf[sizeof(buf) - 1] = 0;
+
        p = strchr(buf, '\n');
+       ATF_REQUIRE(p != NULL);
+       ATF_REQUIRE(p < buf + sizeof(buf) - 2);
        p += 2;
        q = strchr(p, '\n');
+       ATF_REQUIRE(q != NULL);
        *q = '\0';
        ATF_CHECK_STREQ(p, "None.");
 
        isc_mem_debugging = ISC_MEM_DEBUGRECORD;
        isc_test_end();
-
 }
 
 ATF_TC(isc_mem_recordflag);
@@ -203,7 +207,6 @@ ATF_TC_BODY(isc_mem_recordflag, tc) {
        char buf[4096], *p;
        FILE *f;
        void *ptr;
-       size_t size;
 
        result = isc_stdio_open("mem.output", "w", &f);
        ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
@@ -224,14 +227,19 @@ ATF_TC_BODY(isc_mem_recordflag, tc) {
        memset(buf, 0, sizeof(buf));
        result = isc_stdio_open("mem.output", "r", &f);
        ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
-       result = isc_stdio_read(buf, sizeof(buf), 1, f, &size);
+       result = isc_stdio_read(buf, sizeof(buf), 1, f, NULL);
        ATF_REQUIRE_EQ(result, ISC_R_EOF);
        isc_stdio_close(f);
        isc_file_remove("mem.output");
 
+       buf[sizeof(buf) - 1] = 0;
+
        p = strchr(buf, '\n');
+       ATF_REQUIRE(p != NULL);
+       ATF_REQUIRE(p < buf + sizeof(buf) - 2);
        ATF_CHECK(strncmp(p + 2, "ptr ", 4) == 0);
        p = strchr(p + 1, '\n');
+       ATF_REQUIRE(p != NULL);
        ATF_CHECK(strlen(p) == 1);
 
        isc_test_end();
@@ -248,7 +256,6 @@ ATF_TC_BODY(isc_mem_traceflag, tc) {
        char buf[4096], *p;
        FILE *f;
        void *ptr;
-       size_t size;
 
        /* redirect stderr so we can check trace output */
        f = freopen("mem.output", "w", stderr);
@@ -268,9 +275,10 @@ ATF_TC_BODY(isc_mem_traceflag, tc) {
        isc_mem_destroy(&mctx2);
        isc_stdio_close(f);
 
+       memset(buf, 0, sizeof(buf));
        result = isc_stdio_open("mem.output", "r", &f);
        ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
-       result = isc_stdio_read(buf, sizeof(buf), 1, f, &size);
+       result = isc_stdio_read(buf, sizeof(buf), 1, f, NULL);
        ATF_REQUIRE_EQ(result, ISC_R_EOF);
        isc_stdio_close(f);
        isc_file_remove("mem.output");
@@ -278,11 +286,17 @@ ATF_TC_BODY(isc_mem_traceflag, tc) {
        /* return stderr to TTY so we can see errors */
        f = freopen("/dev/tty", "w", stderr);
 
+       buf[sizeof(buf) - 1] = 0;
+
        ATF_CHECK(strncmp(buf, "add ", 4) == 0);
        p = strchr(buf, '\n');
+       ATF_REQUIRE(p != NULL);
        p = strchr(p + 1, '\n');
+       ATF_REQUIRE(p != NULL);
+       ATF_REQUIRE(p < buf + sizeof(buf) - 2);
        ATF_CHECK(strncmp(p + 2, "ptr ", 4) == 0);
        p = strchr(p + 1, '\n');
+       ATF_REQUIRE(p != NULL);
        ATF_CHECK(strncmp(p + 1, "del ", 4) == 0);
 
        isc_mem_debugging = ISC_MEM_DEBUGRECORD;