Copilot commented on code in PR #13708:
URL: https://github.com/apache/trafficserver/pull/13708#discussion_r4234954514


##########
plugins/experimental/access_control/access_control.cc:
##########
@@ -23,12 +23,117 @@
 
 #include <iostream>
 #include <string>
+#include <charconv>
 
 #include "access_control.h"
 
 size_t calcMessageDigest(const StringView hf, const char *secret, const char 
*message, size_t messageLen, char *buffer, size_t len);
 const char *getSecretMap(const StringMap &map, const StringView &key, size_t 
&secretSize);
 
+static bool
+normalizePath(StringView path, String &normalized, bool isScope = false)
+{
+  normalized.clear();
+  if (path.empty()) {
+    normalized = "/";
+    return true;
+  }
+
+  normalized.reserve(path.size() + 1);
+  std::vector<size_t> segment_starts;
+  size_t              i = 0;
+
+  while (i < path.size()) {
+    while (i < path.size() && (path[i] == '/' || path[i] == '\\')) {
+      ++i;
+    }
+    if (i >= path.size()) {
+      break;
+    }
+
+    size_t seg_start = normalized.size();
+    normalized.push_back('/');
+
+    while (i < path.size() && path[i] != '/' && path[i] != '\\') {
+      if (path[i] == '%') {
+        unsigned int val = 0;
+        auto [end, ec] = std::from_chars(path.data() + i + 1, path.data() + i 
+ 3, val, 16);

Review Comment:
   For a trailing `%` (or only one character after it), `path.data() + i + 3` 
is formed beyond the one-past-end pointer before `from_chars` runs. The new `%` 
test exercises this path, so malformed scope/request input can trigger 
undefined behavior; check that two hex characters remain before forming these 
pointers.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to