From 7662353fe0cfc957319930c79f47cdea9a9eb2e8 Mon Sep 17 00:00:00 2001 From: Otto Moerbeek Date: Wed, 17 Jul 2024 11:54:27 +0200 Subject: [PATCH] Yahttp router: avoid unsigned underflow in route() --- ext/yahttp/yahttp/router.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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; -- 2.47.2