Procházet zdrojové kódy

Try to parse port with strtol instead of sscanf

This is needed for the upcoming Zephyr port which does not support
sscanf properly. It is put in a separate commit so it can be easily
reverted once Zephyr has a better implementation.
Tomasz Gorochowik před 6 roky
rodič
revize
2aa40212c3
1 změnil soubory, kde provedl 4 přidání a 1 odebrání
  1. 4 1
      src/civetweb.c

+ 4 - 1
src/civetweb.c

@@ -14305,6 +14305,7 @@ parse_port_string(const struct vec *vec, struct socket *so, int *ip_version)
 	unsigned int a, b, c, d, port;
 	int ch, len;
 	const char *cb;
+	char *endptr;
 #if defined(USE_IPV6)
 	char buf[100] = {0};
 #endif
@@ -14358,7 +14359,9 @@ parse_port_string(const struct vec *vec, struct socket *so, int *ip_version)
 		*ip_version = 4;
 #endif
 
-	} else if (sscanf(vec->ptr, "%u%n", &port, &len) == 1) {
+	} else if (is_valid_port(port = strtoul(vec->ptr, &endptr, 0))
+		   && vec->ptr != endptr) {
+		len = endptr - vec->ptr;
 		/* If only port is specified, bind to IPv4, INADDR_ANY */
 		so->lsa.sin.sin_port = htons((uint16_t)port);
 		*ip_version = 4;