]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Really fuzz isc_lex_getmastertoken() in the test
authorOndřej Surý <ondrej@sury.org>
Wed, 12 Aug 2020 09:29:30 +0000 (11:29 +0200)
committerOndřej Surý <ondrej@isc.org>
Wed, 12 Aug 2020 19:49:31 +0000 (21:49 +0200)
There was a copy&paste error in fuzz/isc_lex_getmastertoken.c where we
didn't really test the function we wanted to test.  Update the test to
have the input data to always include expected 'tokentype' in the first
byte, `eol` argument in the second byte and the rest of the input is the
data to parse.

fuzz/isc_lex_getmastertoken.c
fuzz/isc_lex_getmastertoken.in/named.conf
fuzz/isc_lex_getmastertoken.in/simple

index 75a23295854f7ec6e147c658251f495d551a1acd..a9beb7d681dff0d2c453a49e62677817ba8dd567 100644 (file)
@@ -15,6 +15,7 @@
 #include <isc/buffer.h>
 #include <isc/lex.h>
 #include <isc/mem.h>
+#include <isc/string.h>
 #include <isc/util.h>
 
 #include "fuzz.h"
@@ -46,6 +47,20 @@ int
 LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
        isc_buffer_t buf;
        isc_result_t result;
+       isc_tokentype_t expect;
+       bool eol;
+
+       if (size < sizeof(expect) + sizeof(eol)) {
+               return (0);
+       }
+
+       (void)memmove(&expect, data, sizeof(expect));
+       data += sizeof(expect);
+       size -= sizeof(expect);
+
+       (void)memmove(&eol, data, sizeof(eol));
+       data += sizeof(eol);
+       size -= sizeof(eol);
 
        isc_buffer_constinit(&buf, data, size);
        isc_buffer_add(&buf, size);
@@ -55,7 +70,7 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
 
        do {
                isc_token_t token;
-               result = isc_lex_gettoken(lex, 0, &token);
+               result = isc_lex_getmastertoken(lex, &token, expect, eol);
        } while (result == ISC_R_SUCCESS);
 
        return (0);
index f7d39fdabe83183099e8325f684389e1ab2a3b96..de8ea9c07dfcdd132d9334cacb7d81c9615539e4 100644 (file)
Binary files a/fuzz/isc_lex_getmastertoken.in/named.conf and b/fuzz/isc_lex_getmastertoken.in/named.conf differ
index 105e53a3dcf20774b932ce0f1b607c89c50d08b2..a5eb98cd6f6f10f9793768ef8c8e9d092420769f 100644 (file)
Binary files a/fuzz/isc_lex_getmastertoken.in/simple and b/fuzz/isc_lex_getmastertoken.in/simple differ