]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
cookies: optimize control character check
authorDaniel Gustafsson <daniel@yesql.se>
Mon, 24 Oct 2022 09:31:08 +0000 (11:31 +0200)
committerDaniel Gustafsson <daniel@yesql.se>
Mon, 24 Oct 2022 09:31:08 +0000 (11:31 +0200)
When checking for invalid octets the strcspn() call will return the
position of the first found invalid char or the first NULL byte.
This means that we can check the indicated position in the search-
string saving a strlen() call.

Closes: #9736
Reviewed-by: Jay Satiro <raysatiro@yahoo.com>
lib/cookie.c

index 7f23b417b72d03fbaae0222d4aa36b929c2a083d..8eaedeeb7f98042b0a2d69deb437e0328acbefdc 100644 (file)
@@ -458,11 +458,10 @@ static int invalid_octets(const char *p)
     "\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14"
     "\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x7f"
   };
-  size_t vlen, len;
+  size_t len;
   /* scan for all the octets that are *not* in cookie-octet */
   len = strcspn(p, badoctets);
-  vlen = strlen(p);
-  return (len != vlen);
+  return (p[len] != '\0');
 }
 
 /*