]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
cookie: simplify invalid_octets()
authorDaniel Stenberg <daniel@haxx.se>
Wed, 12 Feb 2025 14:36:22 +0000 (15:36 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Thu, 13 Feb 2025 11:49:13 +0000 (12:49 +0100)
should also make it marginally faster and smaller.

Closes #16306

lib/cookie.c

index 9819768454f3725e3e91a362b1c5c4a3608fcea0..556eec4ab6d6cba399d848949424dfe7e01bcbf0 100644 (file)
@@ -461,15 +461,12 @@ static bool bad_domain(const char *domain, size_t len)
 static bool invalid_octets(const char *p)
 {
   /* Reject all bytes \x01 - \x1f (*except* \x09, TAB) + \x7f */
-  static const char badoctets[] = {
-    "\x01\x02\x03\x04\x05\x06\x07\x08\x0a"
-    "\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14"
-    "\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x7f"
-  };
-  size_t len;
-  /* scan for all the octets that are *not* in cookie-octet */
-  len = strcspn(p, badoctets);
-  return p[len] != '\0';
+  while(*p) {
+    if(((*p != 9) && (*p < 0x20)) || (*p == 0x7f))
+      return TRUE;
+    p++;
+  }
+  return FALSE;
 }
 
 #define CERR_OK            0