Commit 7175f71e2d for bind

commit 7175f71e2d334682d9930e8656292d5929352a62
Author: Petr Špaček <pspacek@isc.org>
Date:   Wed Nov 4 10:02:48 2026 +0000

    Release lexer state after each fuzz input

    Persistent lexers retained input sources and parser state between
    iterations, causing memory growth and making inputs affect later runs.

    Assisted-by: Codex:gpt-6

diff --git a/fuzz/dns_rdata_fromwire_text.c b/fuzz/dns_rdata_fromwire_text.c
index 632886538c..f56436c6a3 100644
--- a/fuzz/dns_rdata_fromwire_text.c
+++ b/fuzz/dns_rdata_fromwire_text.c
@@ -40,21 +40,10 @@ bool debug = false;
  */

 static isc_mem_t *mctx = NULL;
-static isc_lex_t *lex = NULL;

 int
 LLVMFuzzerInitialize(int *argc ISC_ATTR_UNUSED, char ***argv ISC_ATTR_UNUSED) {
-	isc_lexspecials_t specials;
-
 	isc_mem_create("fuzz", &mctx);
-	isc_lex_create(mctx, 64, &lex);
-
-	memset(specials, 0, sizeof(specials));
-	specials['('] = 1;
-	specials[')'] = 1;
-	specials['"'] = 1;
-	isc_lex_setspecials(lex, specials);
-	isc_lex_setcomments(lex, ISC_LEXCOMMENT_DNSMASTERFILE);

 	return 0;
 }
@@ -75,6 +64,8 @@ nullmsg(dns_rdatacallbacks_t *cb, const char *fmt, ...) {

 int
 LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
+	isc_lex_t *lex = NULL;
+	isc_lexspecials_t specials;
 	char totext[64 * 1044 * 4];
 	dns_compress_t cctx;
 	dns_rdatatype_t rdtype;
@@ -162,6 +153,14 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
 	/*
 	 * Convert to wire from text.
 	 */
+	isc_lex_create(mctx, 64, &lex);
+	memset(specials, 0, sizeof(specials));
+	specials['('] = 1;
+	specials[')'] = 1;
+	specials['"'] = 1;
+	isc_lex_setspecials(lex, specials);
+	isc_lex_setcomments(lex, ISC_LEXCOMMENT_DNSMASTERFILE);
+
 	isc_buffer_constinit(&source, totext, isc_buffer_usedlength(&target));
 	isc_buffer_add(&source, isc_buffer_usedlength(&target));
 	CHECK(isc_lex_openbuffer(lex, &source));
@@ -169,6 +168,7 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
 	isc_buffer_init(&target, fromtext, sizeof(fromtext));
 	result = dns_rdata_fromtext(&rdata2, rdclass, rdtype, lex, dns_rootname,
 				    0, mctx, &target, &callbacks);
+	isc_lex_close(lex);
 	if (debug && result != ISC_R_SUCCESS) {
 		fprintf(stderr, "'%s'\n", totext);
 	}
@@ -195,6 +195,7 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
 	isc_buffer_init(&target, fromtext, sizeof(fromtext));
 	result = dns_rdata_fromtext(&rdata3, rdclass, rdtype, lex, dns_rootname,
 				    0, mctx, &target, &callbacks);
+	isc_lex_close(lex);
 	assert(result == ISC_R_SUCCESS);
 	assert(rdata3.length == size);
 	assert(!memcmp(rdata3.data, data, size));
@@ -211,5 +212,8 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
 	assert(!memcmp(target.base, data, size));

 cleanup:
+	if (lex != NULL) {
+		isc_lex_destroy(&lex);
+	}
 	return 0;
 }
diff --git a/fuzz/isc_lex_getmastertoken.c b/fuzz/isc_lex_getmastertoken.c
index 1fa5803d66..e53cede719 100644
--- a/fuzz/isc_lex_getmastertoken.c
+++ b/fuzz/isc_lex_getmastertoken.c
@@ -31,18 +31,17 @@ int
 LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);

 static isc_mem_t *mctx = NULL;
-static isc_lex_t *lex = NULL;

 int
 LLVMFuzzerInitialize(int *argc ISC_ATTR_UNUSED, char ***argv ISC_ATTR_UNUSED) {
 	isc_mem_create("fuzz", &mctx);
-	isc_lex_create(mctx, 1024, &lex);

 	return 0;
 }

 int
 LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
+	isc_lex_t *lex = NULL;
 	isc_buffer_t buf;
 	isc_result_t result;
 	isc_token_t token;
@@ -61,6 +60,8 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
 	data += 1;
 	size -= 1;

+	isc_lex_create(mctx, 1024, &lex);
+
 	isc_buffer_constinit(&buf, data, size);
 	isc_buffer_add(&buf, size);
 	isc_buffer_setactive(&buf, size);
@@ -72,5 +73,6 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
 	} while (result == ISC_R_SUCCESS && token.type != isc_tokentype_eof);

 cleanup:
+	isc_lex_destroy(&lex);
 	return 0;
 }
diff --git a/fuzz/isc_lex_gettoken.c b/fuzz/isc_lex_gettoken.c
index a574368df2..857870f8e3 100644
--- a/fuzz/isc_lex_gettoken.c
+++ b/fuzz/isc_lex_gettoken.c
@@ -24,21 +24,22 @@
 bool debug = false;

 static isc_mem_t *mctx = NULL;
-static isc_lex_t *lex = NULL;

 int
 LLVMFuzzerInitialize(int *argc ISC_ATTR_UNUSED, char ***argv ISC_ATTR_UNUSED) {
 	isc_mem_create("fuzz", &mctx);
-	isc_lex_create(mctx, 1024, &lex);

 	return 0;
 }

 int
 LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
+	isc_lex_t *lex = NULL;
 	isc_buffer_t buf;
 	isc_result_t result;

+	isc_lex_create(mctx, 1024, &lex);
+
 	isc_buffer_constinit(&buf, data, size);
 	isc_buffer_add(&buf, size);
 	isc_buffer_setactive(&buf, size);
@@ -51,5 +52,6 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
 	} while (result == ISC_R_SUCCESS);

 cleanup:
+	isc_lex_destroy(&lex);
 	return 0;
 }