From: Mark Andrews Date: Tue, 7 Apr 2026 22:57:05 +0000 (+1000) Subject: Fix strstr const inheritance issue in test code X-Git-Tag: v9.20.23~47^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5ccfb936cae94108d59508a01cd921881429b0c0;p=thirdparty%2Fbind9.git Fix strstr const inheritance issue in test code A strstr call discarded the const attribute. Rework the code preserving the const attribute. --- diff --git a/bin/tests/system/rpz/testlib/test-data.c b/bin/tests/system/rpz/testlib/test-data.c index 8ccebd6579e..7d3c625f7be 100644 --- a/bin/tests/system/rpz/testlib/test-data.c +++ b/bin/tests/system/rpz/testlib/test-data.c @@ -865,8 +865,8 @@ apply_update(const char *updstr, trpz_result_t **presults, size_t *pnresults, } } else if (!strcasecmp(rrbuf, "TXT")) { - char *ftext = NULL; - + const char *ftext = NULL; + size_t len; ftext = strstr(updstr, databuf); if (ftext == NULL) { fprintf(stderr, "Error parsing TXT record: \"%s\"\n", @@ -875,15 +875,19 @@ apply_update(const char *updstr, trpz_result_t **presults, size_t *pnresults, } if (*ftext == '"') { - *ftext++ = 0; + ftext++; - if (ftext[strlen(ftext) - 1] == '"') { - ftext[strlen(ftext) - 1] = 0; + len = strlen(ftext); + if (len > 0 && ftext[len - 1] == '"') { + len--; } + } else { + len = strlen(ftext); } - strncpy(databuf, ftext, sizeof(databuf)); - databuf[sizeof(databuf) - 1] = 0; + strncpy(databuf, ftext, + len < sizeof(databuf) ? len : sizeof(databuf)); + databuf[len < sizeof(databuf) ? len : sizeof(databuf) - 1] = 0; policy = LIBRPZ_POLICY_RECORD; } else if (!strcasecmp(rrbuf, "DNAME")) { policy = LIBRPZ_POLICY_RECORD;