From: Otto Moerbeek Date: Wed, 17 Jul 2024 09:54:27 +0000 (+0200) Subject: Yahttp router: avoid unsigned underflow in route() X-Git-Tag: rec-4.9.8~2^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F14480%2Fhead;p=thirdparty%2Fpdns.git Yahttp router: avoid unsigned underflow in route() --- diff --git a/ext/yahttp/yahttp/router.cpp b/ext/yahttp/yahttp/router.cpp index 18ea9b6fcf..e16a0d48da 100644 --- a/ext/yahttp/yahttp/router.cpp +++ b/ext/yahttp/yahttp/router.cpp @@ -63,8 +63,16 @@ namespace YaHTTP { while(k2 < static_cast(req->url.path.size()) && req->url.path[k2] != url[k1+1]) k2++; pos2 = k2; params[pname] = funcptr::tie(pos1,pos2); + if (k2 > 0) { + k2--; + } + else { + // If k2 is zero, do not decrement it and then increment at bottom of loop + // Only increment k1 and continue loop + k1++; + continue; + } } - k2--; } else if (url[k1] != req->url.path[k2]) { break;