]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: http: add new function http_path_has_forbidden_char()
authorWilly Tarreau <w@1wt.eu>
Tue, 8 Aug 2023 13:24:54 +0000 (15:24 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 8 Aug 2023 17:10:54 +0000 (19:10 +0200)
As its name implies, this function checks if a path component has any
forbidden headers starting at the designated location. The goal is to
seek from the result of a successful ist_find_range() for more precise
chars. Here we're focusing on 0x00-0x1F, 0x20 and 0x23 to make sure
we're not too strict at this point.

include/haproxy/http.h

index e48e21fae86e656800ea9eb536862270d5537346..e2ba2e515a9624628c2e039a09b80e12e7e5c2ac 100644 (file)
@@ -190,6 +190,25 @@ static inline int http_header_has_forbidden_char(const struct ist ist, const cha
        return 0;
 }
 
+/* Looks into <ist> for forbidden characters for :path values (0x00..0x1F,
+ * 0x20, 0x23), starting at pointer <start> which must be within <ist>.
+ * Returns non-zero if such a character is found, 0 otherwise. When run on
+ * unlikely header match, it's recommended to first check for the presence
+ * of control chars using ist_find_ctl().
+ */
+static inline int http_path_has_forbidden_char(const struct ist ist, const char *start)
+{
+       do {
+               if ((uint8_t)*start <= 0x23) {
+                       if ((uint8_t)*start < 0x20)
+                               return 1;
+                       if ((1U << ((uint8_t)*start & 0x1F)) & ((1<<3) | (1<<0)))
+                               return 1;
+               }
+               start++;
+       } while (start < istend(ist));
+       return 0;
+}
 
 #endif /* _HAPROXY_HTTP_H */