]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Fix parser test (missing string termination)
authorOndřej Surý <ondrej@isc.org>
Wed, 5 Nov 2025 11:39:43 +0000 (12:39 +0100)
committerColin Vidal <colin@isc.org>
Wed, 5 Nov 2025 12:06:38 +0000 (13:06 +0100)
Parser test could crash because the `dumpb2` buffer hasn't explicit C
NULL string termination after dumping the configuration tree in it.
`cfg_printx` does not doing this by default.

Fix the test by comparing only the strings written with strncmp.

tests/isccfg/parser_test.c

index 5b334f14d826dde76f3711e62133d1055b9933c1..e1e6beb093b6d13ce7d9ec6827614dbc113f8375 100644 (file)
@@ -221,8 +221,10 @@ ISC_RUN_TEST_IMPL(cfg_clone_copy) {
        isc_buffer_t buf;
        isc_buffer_t dumpb1;
        char dumpbdata1[10024];
+       size_t dumpblen1;
        isc_buffer_t dumpb2;
        char dumpbdata2[10024];
+       size_t dumpblen2;
 
        /*
         * This is a modified subset of the default conf which contains
@@ -266,13 +268,14 @@ view \"_bind\" chaos {\n\
 
        isc_buffer_init(&dumpb1, dumpbdata1, sizeof(dumpbdata1));
        cfg_printx(orig, 0, cfg_clone_copy_dumpconf, &dumpb1);
-       isc_buffer_putuint8(&dumpb1, 0);
 
        /*
         * The point of the test is not really to test the stringify code of the
         * cfg_obj_t tree, but let's do it as a sanity check first.
         */
-       assert_int_equal(strcmp(conf, dumpbdata1), 0);
+       dumpblen1 = isc_buffer_remaininglength(&dumpb1);
+       assert_int_equal(sizeof(conf) - 1, dumpblen1);
+       assert_memory_equal(conf, dumpbdata1, dumpblen1);
 
        /*
         * The original tree can be freed anytime, it is not connected in any
@@ -288,7 +291,10 @@ view \"_bind\" chaos {\n\
        isc_buffer_init(&dumpb2, dumpbdata2, sizeof(dumpbdata2));
        cfg_printx(clone, 0, cfg_clone_copy_dumpconf, &dumpb2);
 
-       assert_int_equal(strcmp(dumpbdata1, dumpbdata2), 0);
+       dumpblen1 = isc_buffer_remaininglength(&dumpb1);
+       dumpblen2 = isc_buffer_remaininglength(&dumpb2);
+       assert_int_equal(dumpblen1, dumpblen2);
+       assert_memory_equal(dumpbdata1, dumpbdata2, dumpblen1);
 
        cfg_obj_detach(&clone);
 }