Browse Source

Merge branch 'master' of https://github.com/civetweb/civetweb

bel2125 5 years ago
parent
commit
07f97de2e4
3 changed files with 36 additions and 12 deletions
  1. 1 1
      resources/coverity_check.sh
  2. 16 9
      src/civetweb.c
  3. 19 2
      unittest/public_server.c

+ 1 - 1
resources/coverity_check.sh

@@ -31,7 +31,7 @@ cp resources/Makefile.in-os cov_build/resources/
 cd cov_build
 cd cov_build
 
 
 # new scan build
 # new scan build
-../../cov-analysis-linux64-2017.07/bin/cov-build  --dir cov-int make WITH_IPV6=1 WITH_WEBSOCKET=1 WITH_SERVER_STATS=1 WITH_EXPERIMENTAL=1
+../../cov-analysis-linux64-2019.03/bin/cov-build  --dir cov-int make WITH_IPV6=1 WITH_WEBSOCKET=1 WITH_SERVER_STATS=1 WITH_EXPERIMENTAL=1
 
 
 
 
 # pack build results for upload
 # pack build results for upload

+ 16 - 9
src/civetweb.c

@@ -234,6 +234,9 @@ static void DEBUG_TRACE_FUNC(const char *func,
 	DEBUG_TRACE_FUNC(__func__, __LINE__, fmt, __VA_ARGS__)
 	DEBUG_TRACE_FUNC(__func__, __LINE__, fmt, __VA_ARGS__)
 
 
 #define NEED_DEBUG_TRACE_FUNC
 #define NEED_DEBUG_TRACE_FUNC
+#ifndef DEBUG_TRACE_STREAM
+# define DEBUG_TRACE_STREAM   stdout
+#endif
 
 
 #else
 #else
 #define DEBUG_TRACE(fmt, ...)                                                  \
 #define DEBUG_TRACE(fmt, ...)                                                  \
@@ -1743,8 +1746,8 @@ DEBUG_TRACE_FUNC(const char *func, unsigned line, const char *fmt, ...)
 		nslast = nsnow;
 		nslast = nsnow;
 	}
 	}
 
 
-	flockfile(stdout);
-	printf("*** %lu.%09lu %12" INT64_FMT " %lu %s:%u: ",
+	flockfile(DEBUG_TRACE_STREAM);
+	fprintf( DEBUG_TRACE_STREAM,"*** %lu.%09lu %12" INT64_FMT " %lu %s:%u: ",
 	       (unsigned long)tsnow.tv_sec,
 	       (unsigned long)tsnow.tv_sec,
 	       (unsigned long)tsnow.tv_nsec,
 	       (unsigned long)tsnow.tv_nsec,
 	       nsnow - nslast,
 	       nsnow - nslast,
@@ -1752,11 +1755,11 @@ DEBUG_TRACE_FUNC(const char *func, unsigned line, const char *fmt, ...)
 	       func,
 	       func,
 	       line);
 	       line);
 	va_start(args, fmt);
 	va_start(args, fmt);
-	vprintf(fmt, args);
+	vfprintf(DEBUG_TRACE_STREAM, fmt, args);
 	va_end(args);
 	va_end(args);
-	putchar('\n');
-	fflush(stdout);
-	funlockfile(stdout);
+	putc('\n', DEBUG_TRACE_STREAM);
+	fflush(DEBUG_TRACE_STREAM);
+	funlockfile(DEBUG_TRACE_STREAM);
 	nslast = nsnow;
 	nslast = nsnow;
 }
 }
 #endif /* NEED_DEBUG_TRACE_FUNC */
 #endif /* NEED_DEBUG_TRACE_FUNC */
@@ -1810,6 +1813,9 @@ typedef struct SSL_CTX SSL_CTX;
  *
  *
  * #define OPENSSL_free free */
  * #define OPENSSL_free free */
 #define free free
 #define free free
+// disable for boringssl
+#define CONF_modules_unload(a) ((void)0)
+#define ENGINE_cleanup() ((void)0)
 #endif
 #endif
 
 
 #if (OPENSSL_VERSION_NUMBER >= 0x10100000L)
 #if (OPENSSL_VERSION_NUMBER >= 0x10100000L)
@@ -9556,7 +9562,7 @@ static void *
 realloc2(void *ptr, size_t size)
 realloc2(void *ptr, size_t size)
 {
 {
 	void *new_ptr = mg_realloc(ptr, size);
 	void *new_ptr = mg_realloc(ptr, size);
-	if (new_ptr == NULL) {
+	if ((new_ptr == NULL) && (size > 0)) {
 		mg_free(ptr);
 		mg_free(ptr);
 	}
 	}
 	return new_ptr;
 	return new_ptr;
@@ -17096,8 +17102,8 @@ mg_connect_client2(const char *host,
 	opts.port = port;
 	opts.port = port;
 	return mg_connect_client_impl(&opts,
 	return mg_connect_client_impl(&opts,
 	                              is_ssl,
 	                              is_ssl,
-	                              error->text,
-	                              error->text_buffer_size);
+	                              ((error != NULL) ? error->text : NULL),
+	                              ((error != NULL) ? error->text_buffer_size : 0));
 }
 }
 #endif
 #endif
 
 
@@ -19711,6 +19717,7 @@ mg_start_domain2(struct mg_context *ctx,
 				            config_options[AUTHENTICATION_DOMAIN].name);
 				            config_options[AUTHENTICATION_DOMAIN].name);
 			}
 			}
 			mg_free(new_dom);
 			mg_free(new_dom);
+			mg_unlock_context(ctx);
 			return -5;
 			return -5;
 		}
 		}
 
 

+ 19 - 2
unittest/public_server.c

@@ -1,4 +1,4 @@
-/* Copyright (c) 2015-2018 the Civetweb developers
+/* Copyright (c) 2015-2020 the Civetweb developers
  *
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
  * of this software and associated documentation files (the "Software"), to deal
@@ -785,8 +785,25 @@ START_TEST(test_mg_server_and_client_tls)
 	client_conn =
 	client_conn =
 	    mg_connect_client("127.0.0.1", 8443, 1, client_err, sizeof(client_err));
 	    mg_connect_client("127.0.0.1", 8443, 1, client_err, sizeof(client_err));
 
 
-	ck_assert_str_ne(client_err, "");
+	/* cannot connect without client certificate */
+#if defined(__MACH__)
+	/* except for Apple (maybe this is specific to the MacOS container on TravisCI?) */
+	if (client_conn) {
+		mg_printf(client_conn, "GET / HTTP/1.0\r\n\r\n");
+		client_res =
+		    mg_get_response(client_conn, client_err, sizeof(client_err), 10000);
+		ck_assert_int_lt(client_res, 0); /* response is "error" (-1) */
+		ck_assert_str_ne(client_err, "");
+		client_ri = mg_get_response_info(client_conn);
+		ck_assert(client_ri == NULL);
+		
+		mg_close_connection(client_conn);
+		client_conn = NULL;
+		strcpy(client_err, "OpenSSL on MacOS allows to connect without a mandatory client certificate, but not data exchange");
+	}
+#endif
 	ck_assert(client_conn == NULL);
 	ck_assert(client_conn == NULL);
+	ck_assert_str_ne(client_err, "");
 
 
 	memset(client_err, 0, sizeof(client_err));
 	memset(client_err, 0, sizeof(client_err));
 	memset(&client_options, 0, sizeof(client_options));
 	memset(&client_options, 0, sizeof(client_options));