From d79e1d7fbcbb332c92a8f8a85cc7a1f048f2a656 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 27 Apr 2026 22:49:31 +0800 Subject: [PATCH] FFstrbuf: improves robustness of `ffStrbufMatchSeparatedNS` Co-authored-by: Copilot --- src/common/impl/FFstrbuf.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/common/impl/FFstrbuf.c b/src/common/impl/FFstrbuf.c index a53079055..d0a38f9ce 100644 --- a/src/common/impl/FFstrbuf.c +++ b/src/common/impl/FFstrbuf.c @@ -790,9 +790,10 @@ bool ffStrbufMatchSeparatedNS(const FFstrbuf* strbuf, uint32_t compLength, const } for (const char* p = comp; p < comp + compLength;) { - const char* colon = memchr(p, separator, compLength); + const char* colon = memchr(p, separator, (size_t)(comp + compLength - p)); if (colon == NULL) { - return strcmp(strbuf->chars, p) == 0; + uint32_t remainingLen = (uint32_t)(comp + compLength - p); + return strbuf->length == remainingLen && memcmp(strbuf->chars, p, remainingLen) == 0; } uint32_t substrLength = (uint32_t) (colon - p); @@ -817,9 +818,10 @@ bool ffStrbufMatchSeparatedIgnCaseNS(const FFstrbuf* strbuf, uint32_t compLength } for (const char* p = comp; p < comp + compLength;) { - const char* colon = memchr(p, separator, compLength); + const char* colon = memchr(p, separator, (size_t)(comp + compLength - p)); if (colon == NULL) { - return strcasecmp(strbuf->chars, p) == 0; + uint32_t remainingLen = (uint32_t)(comp + compLength - p); + return strbuf->length == remainingLen && strncasecmp(strbuf->chars, p, remainingLen) == 0; } uint32_t substrLength = (uint32_t) (colon - p);