Browse Source

Reset address family if parse_port_string fails

bel 8 năm trước cách đây
mục cha
commit
b38df9d5f2
1 tập tin đã thay đổi với 9 bổ sung2 xóa
  1. 9 2
      src/civetweb.c

+ 9 - 2
src/civetweb.c

@@ -10793,6 +10793,7 @@ parse_port_string(const struct vec *vec, struct socket *so, int *ip_version)
 	/* sscanf and the option splitting code ensure the following condition
 	 */
 	if ((len < 0) && ((unsigned)len > (unsigned)vec->len)) {
+		*ip_version = 0;
 		return 0;
 	}
 	ch = vec->ptr[len]; /* Next character after the port number */
@@ -10800,8 +10801,14 @@ parse_port_string(const struct vec *vec, struct socket *so, int *ip_version)
 	so->ssl_redir = (ch == 'r');
 
 	/* Make sure the port is valid and vector ends with 's', 'r' or ',' */
-	return is_valid_port(port)
-	       && (ch == '\0' || ch == 's' || ch == 'r' || ch == ',');
+	if (is_valid_port(port)
+	    && (ch == '\0' || ch == 's' || ch == 'r' || ch == ',')) {
+		return 1;
+	}
+
+	/* Reset ip_version to 0 of there is an error */
+	*ip_version = 0;
+	return 0;
 }