bel2125 пре 5 година
родитељ
комит
74fe013ee4
2 измењених фајлова са 24 додато и 16 уклоњено
  1. 15 9
      src/civetweb.c
  2. 9 7
      unittest/public_server.c

+ 15 - 9
src/civetweb.c

@@ -4319,15 +4319,17 @@ match_prefix(const char *pattern, size_t pattern_len, const char *str)
 			i++;
 			i++;
 			if (pattern[i] == '*') {
 			if (pattern[i] == '*') {
 				i++;
 				i++;
-				len = strlen(str + j);
+				len = (ptrdiff_t)strlen(str + j);
 			} else {
 			} else {
-				len = strcspn(str + j, "/");
+				len = (ptrdiff_t)strcspn(str + j, "/");
 			}
 			}
 			if (i == (ptrdiff_t)pattern_len) {
 			if (i == (ptrdiff_t)pattern_len) {
 				return j + len;
 				return j + len;
 			}
 			}
 			do {
 			do {
-				res = match_prefix(pattern + i, pattern_len - i, str + j + len);
+				res = match_prefix(pattern + i,
+				                   (pattern_len - (size_t)i),
+				                   str + j + len);
 			} while (res == -1 && len-- > 0);
 			} while (res == -1 && len-- > 0);
 			return (res == -1) ? -1 : j + res + len;
 			return (res == -1) ? -1 : j + res + len;
 		} else if (lowercase(&pattern[i]) != lowercase(&str[j])) {
 		} else if (lowercase(&pattern[i]) != lowercase(&str[j])) {
@@ -6920,7 +6922,7 @@ mg_read(struct mg_connection *conn, void *buf, size_t len)
 				}
 				}
 
 
 				/* append a new chunk */
 				/* append a new chunk */
-				conn->content_len += chunkSize;
+				conn->content_len += (int64_t)chunkSize;
 			}
 			}
 		}
 		}
 
 
@@ -14654,7 +14656,9 @@ close_all_listening_sockets(struct mg_context *ctx)
 static int
 static int
 parse_port_string(const struct vec *vec, struct socket *so, int *ip_version)
 parse_port_string(const struct vec *vec, struct socket *so, int *ip_version)
 {
 {
-	unsigned int a, b, c, d, port;
+	unsigned int a, b, c, d;
+	unsigned port;
+	unsigned long portUL;
 	int ch, len;
 	int ch, len;
 	const char *cb;
 	const char *cb;
 	char *endptr;
 	char *endptr;
@@ -14711,9 +14715,10 @@ parse_port_string(const struct vec *vec, struct socket *so, int *ip_version)
 		*ip_version = 4;
 		*ip_version = 4;
 #endif
 #endif
 
 
-	} else if (is_valid_port(port = strtoul(vec->ptr, &endptr, 0))
-	           && vec->ptr != endptr) {
-		len = endptr - vec->ptr;
+	} else if (is_valid_port(portUL = strtoul(vec->ptr, &endptr, 0))
+	           && (vec->ptr != endptr)) {
+		len = (int)(endptr - vec->ptr);
+		port = (uint16_t)portUL;
 		/* If only port is specified, bind to IPv4, INADDR_ANY */
 		/* If only port is specified, bind to IPv4, INADDR_ANY */
 		so->lsa.sin.sin_port = htons((uint16_t)port);
 		so->lsa.sin.sin_port = htons((uint16_t)port);
 		*ip_version = 4;
 		*ip_version = 4;
@@ -19250,7 +19255,8 @@ static
 		pthread_setspecific(sTlsKey, NULL);
 		pthread_setspecific(sTlsKey, NULL);
 		return NULL;
 		return NULL;
 	}
 	}
-	ctx->squeue = (struct socket *)mg_calloc(itmp, sizeof(struct socket));
+	ctx->squeue =
+	    (struct socket *)mg_calloc((unsigned int)itmp, sizeof(struct socket));
 	if (ctx->squeue == NULL) {
 	if (ctx->squeue == NULL) {
 		mg_cry_ctx_internal(ctx,
 		mg_cry_ctx_internal(ctx,
 		                    "Out of memory: Cannot allocate %s",
 		                    "Out of memory: Cannot allocate %s",

+ 9 - 7
unittest/public_server.c

@@ -920,6 +920,8 @@ request_test_handler2(struct mg_connection *conn, void *cbdata)
 	int err_ret;
 	int err_ret;
 	char url_buffer[128];
 	char url_buffer[128];
 
 
+	(void)cbdata; /* unused */
+
 	ctx = mg_get_context(conn);
 	ctx = mg_get_context(conn);
 	ud = mg_get_user_data(ctx);
 	ud = mg_get_user_data(ctx);
 	ud2 = mg_get_user_context_data(conn);
 	ud2 = mg_get_user_context_data(conn);
@@ -1527,7 +1529,7 @@ START_TEST(test_request_handlers)
 	i = (int)strlen(plain_file_content);
 	i = (int)strlen(plain_file_content);
 	ck_assert_int_eq(i, 17);
 	ck_assert_int_eq(i, 17);
 
 
-	fwrite(plain_file_content, i, 1, f);
+	fwrite(plain_file_content, (size_t)i, 1, f);
 	fclose(f);
 	fclose(f);
 
 
 #ifdef _WIN32
 #ifdef _WIN32
@@ -1617,7 +1619,7 @@ START_TEST(test_request_handlers)
 		        "This file needs to be compiled manually before "
 		        "This file needs to be compiled manually before "
 		        "starting the test\n");
 		        "starting the test\n");
 		fprintf(stderr,
 		fprintf(stderr,
-		        "e.g. by gcc test/cgi_test.c -o output/cgi_test.cgi\n\n");
+		        "e.g. by gcc unittest/cgi_test.c -o output/cgi_test.cgi\n\n");
 
 
 		/* Abort test with diagnostic message */
 		/* Abort test with diagnostic message */
 		ck_abort_msg("Mandatory file %s must be built before starting the test "
 		ck_abort_msg("Mandatory file %s must be built before starting the test "
@@ -1914,7 +1916,7 @@ START_TEST(test_request_handlers)
 
 
 	mg_printf(client_conn,
 	mg_printf(client_conn,
 	          "GET /unknown_url HTTP/1.1\r\n"
 	          "GET /unknown_url HTTP/1.1\r\n"
-	          "Host: localhost\r\n"
+	          "Host: localhost:%u\r\n"
 	          "\r\n",
 	          "\r\n",
 	          ipv4_port);
 	          ipv4_port);
 
 
@@ -1937,7 +1939,7 @@ START_TEST(test_request_handlers)
 
 
 	mg_printf(client_conn,
 	mg_printf(client_conn,
 	          "GET /handler2 HTTP/1.1\r\n"
 	          "GET /handler2 HTTP/1.1\r\n"
-	          "Host: localhost\r\n"
+	          "Host: localhost:%u\r\n"
 	          "\r\n",
 	          "\r\n",
 	          ipv4_port);
 	          ipv4_port);
 
 
@@ -2499,11 +2501,11 @@ field_store(const char *path, long long file_size, void *user_data)
 			char buf[32] = {0};
 			char buf[32] = {0};
 			int r, i;
 			int r, i;
 			for (r = 0; r < myfile_content_rep; r++) {
 			for (r = 0; r < myfile_content_rep; r++) {
-				i = (int)fread(buf, 1, myfile_content_len, f);
+				i = (int)fread(buf, 1, (size_t)myfile_content_len, f);
 				ck_assert_int_eq(i, myfile_content_len);
 				ck_assert_int_eq(i, myfile_content_len);
 				ck_assert_str_eq(buf, myfile_content);
 				ck_assert_str_eq(buf, myfile_content);
 			}
 			}
-			i = (int)fread(buf, 1, myfile_content_len, f);
+			i = (int)fread(buf, 1, (size_t)myfile_content_len, f);
 			ck_assert_int_eq(i, 0);
 			ck_assert_int_eq(i, 0);
 			fclose(f);
 			fclose(f);
 		}
 		}
@@ -4749,7 +4751,7 @@ minimal_http_https_client_impl(const char *server,
 	while (data_read < client_ri->content_length) {
 	while (data_read < client_ri->content_length) {
 		r = mg_read(client,
 		r = mg_read(client,
 		            client_data_buf + data_read,
 		            client_data_buf + data_read,
-		            sizeof(client_data_buf) - data_read);
+		            sizeof(client_data_buf) - (size_t)data_read);
 		if (r > 0) {
 		if (r > 0) {
 			data_read += r;
 			data_read += r;
 			ck_assert_int_lt(data_read, sizeof(client_data_buf));
 			ck_assert_int_lt(data_read, sizeof(client_data_buf));