From 63afaec62901069ea483ad5997fc8f066e562d41 Mon Sep 17 00:00:00 2001 From: Otto Moerbeek Date: Wed, 17 Jul 2024 11:23:19 +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 90612ad8ec62..e9f6beecde45 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;