]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
ensure buffer in NUL terminated for strchr(); check that p != NULL
authorMark Andrews <marka@isc.org>
Sat, 14 Oct 2017 21:32:53 +0000 (08:32 +1100)
committerMark Andrews <marka@isc.org>
Sat, 14 Oct 2017 21:32:53 +0000 (08:32 +1100)
lib/isc/tests/mem_test.c

index 3cb67c6101d7e5259ffd036d44ebdfb9acb80df1..343672f54846c3547b2d68c3f0632dc54138af18 100644 (file)
@@ -248,7 +248,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);
@@ -270,7 +269,8 @@ ATF_TC_BODY(isc_mem_traceflag, tc) {
 
        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);
+       memset(buf, 0, sizeof(buf));
+       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 +278,16 @@ 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_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;