Browse Source

Auto-format code

bel2125 2 months ago
parent
commit
d6110adc81
7 changed files with 103 additions and 89 deletions
  1. 9 7
      fuzztest/fuzzmain.c
  2. 22 11
      src/civetweb.c
  3. 1 2
      src/handle_form.inl
  4. 3 3
      src/mod_gnutls.inl
  5. 13 11
      src/mod_lua.inl
  6. 2 1
      src/mod_mbedtls.inl
  7. 53 54
      unittest/public_server.c

+ 9 - 7
fuzztest/fuzzmain.c

@@ -110,13 +110,14 @@ civetweb_init(void)
 int LLVMFuzzerInitialize(int *argc, char ***argv);
 
 int
-LLVMFuzzerInitialize(int *argc, char ***argv) {
-  // Silence unused args warning.
+LLVMFuzzerInitialize(int *argc, char ***argv)
+{
+	// Silence unused args warning.
 	(void)(argc);
 	(void)(argv);
 
 	civetweb_init();
-  return 0;
+	return 0;
 }
 
 #if defined(TEST_FUZZ1)
@@ -215,7 +216,7 @@ LLVMFuzzerTestOneInput_URI(const uint8_t *data, size_t size)
 {
 	static char URI[1024 * 64]; /* static, to avoid stack overflow */
 
-	if (size+1 < sizeof(URI)) {
+	if (size + 1 < sizeof(URI)) {
 		memcpy(URI, data, size);
 		URI[size] = 0;
 	} else {
@@ -445,13 +446,14 @@ mock_server_init(void)
 int LLVMFuzzerInitialize(int *argc, char ***argv);
 
 int
-LLVMFuzzerInitialize(int *argc, char ***argv) {
-  // Silence unused args warning.
+LLVMFuzzerInitialize(int *argc, char ***argv)
+{
+	// Silence unused args warning.
 	(void)(argc);
 	(void)(argv);
 
 	mock_server_init();
-  return 0;
+	return 0;
 }
 
 

+ 22 - 11
src/civetweb.c

@@ -1595,7 +1595,7 @@ static int mg_openssl_initialized = 0;
 #endif
 #if !defined(OPENSSL_API_1_0) && !defined(OPENSSL_API_1_1)                     \
     && !defined(OPENSSL_API_3_0) && !defined(USE_MBEDTLS)                      \
-	&& !defined(USE_GNUTLS)
+    && !defined(USE_GNUTLS)
 #error "Please define OPENSSL_API_#_# or USE_MBEDTLS or USE_GNUTLS"
 #endif
 #if defined(OPENSSL_API_1_0) && defined(OPENSSL_API_1_1)
@@ -6170,9 +6170,12 @@ push_inner(struct mg_context *ctx,
 		} else
 #elif defined(USE_GNUTLS)
 		if (ssl != NULL) {
-			n = gtls_ssl_write(ssl, (const unsigned char *)buf, (size_t) len);
+			n = gtls_ssl_write(ssl, (const unsigned char *)buf, (size_t)len);
 			if (n < 0) {
-				fprintf(stderr, "SSL write failed (%d): %s", n, gnutls_strerror(n));
+				fprintf(stderr,
+				        "SSL write failed (%d): %s",
+				        n,
+				        gnutls_strerror(n));
 				return -2;
 			} else {
 				err = 0;
@@ -6477,7 +6480,10 @@ pull_inner(FILE *fp,
 		if (pollres > 0) {
 			nread = gtls_ssl_read(conn->ssl, (unsigned char *)buf, to_read);
 			if (nread < 0) {
-				fprintf(stderr, "SSL read failed (%d): %s", nread, gnutls_strerror(nread));
+				fprintf(stderr,
+				        "SSL read failed (%d): %s",
+				        nread,
+				        gnutls_strerror(nread));
 				return -2;
 			} else {
 				err = 0;
@@ -9632,7 +9638,8 @@ connect_socket(
 		return 0;
 	}
 
-#if !defined(NO_SSL) && !defined(USE_MBEDTLS) && !defined(USE_GNUTLS) && !defined(NO_SSL_DL)
+#if !defined(NO_SSL) && !defined(USE_MBEDTLS) && !defined(USE_GNUTLS)          \
+    && !defined(NO_SSL_DL)
 #if defined(OPENSSL_API_1_1) || defined(OPENSSL_API_3_0)
 	if (use_ssl && (TLS_client_method == NULL)) {
 		if (error != NULL) {
@@ -16158,7 +16165,7 @@ set_ports_option(struct mg_context *phys_ctx)
 			                    portsTotal);
 			if (so.is_optional) {
 				portsOk++; /* it's okay if we couldn't create a socket,
-						this port is optional anyway */
+				        this port is optional anyway */
 			}
 			continue;
 		}
@@ -18399,7 +18406,8 @@ mg_close_connection(struct mg_connection *conn)
 
 	close_connection(conn);
 
-#if !defined(NO_SSL) && !defined(USE_MBEDTLS) && !defined(USE_GNUTLS) // TODO: mbedTLS client
+#if !defined(NO_SSL) && !defined(USE_MBEDTLS)                                  \
+    && !defined(USE_GNUTLS) // TODO: mbedTLS client
 	if (((conn->phys_ctx->context_type == CONTEXT_HTTP_CLIENT)
 	     || (conn->phys_ctx->context_type == CONTEXT_WS_CLIENT))
 	    && (conn->phys_ctx->dd.ssl_ctx != NULL)) {
@@ -18501,7 +18509,8 @@ mg_connect_client_impl(const struct mg_client_options *client_options,
 		return NULL;
 	}
 
-#if !defined(NO_SSL) && !defined(USE_MBEDTLS) && !defined(USE_GNUTLS) // TODO: mbedTLS client
+#if !defined(NO_SSL) && !defined(USE_MBEDTLS)                                  \
+    && !defined(USE_GNUTLS) // TODO: mbedTLS client
 #if (defined(OPENSSL_API_1_1) || defined(OPENSSL_API_3_0))                     \
     && !defined(NO_SSL_DL)
 
@@ -18578,7 +18587,8 @@ mg_connect_client_impl(const struct mg_client_options *client_options,
 			            error->text_buffer_size,
 			            "Can not create mutex");
 		}
-#if !defined(NO_SSL) && !defined(USE_MBEDTLS) && !defined(USE_GNUTLS) // TODO: mbedTLS client
+#if !defined(NO_SSL) && !defined(USE_MBEDTLS)                                  \
+    && !defined(USE_GNUTLS) // TODO: mbedTLS client
 		SSL_CTX_free(conn->dom_ctx->ssl_ctx);
 #endif
 		closesocket(sock);
@@ -18586,7 +18596,8 @@ mg_connect_client_impl(const struct mg_client_options *client_options,
 		return NULL;
 	}
 
-#if !defined(NO_SSL) && !defined(USE_MBEDTLS) && !defined(USE_GNUTLS) // TODO: mbedTLS client
+#if !defined(NO_SSL) && !defined(USE_MBEDTLS)                                  \
+    && !defined(USE_GNUTLS) // TODO: mbedTLS client
 	if (use_ssl) {
 		/* TODO: Check ssl_verify_peer and ssl_ca_path here.
 		 * SSL_CTX_set_verify call is needed to switch off server
@@ -22257,7 +22268,7 @@ mg_get_system_info(char *buffer, int buflen)
 		            sizeof(block),
 		            ",%s\"os\" : \"%s %s\"",
 		            eol,
-		           "RTEMS",
+		            "RTEMS",
 		            rtems_version());
 		system_info_length += mg_str_append(&buffer, end, block);
 #elif defined(__ZEPHYR__)

+ 1 - 2
src/handle_form.inl

@@ -757,8 +757,7 @@ mg_handle_form_request(struct mg_connection *conn,
 
 			/* after the transport padding, if the boundary isn't
 			 * immediately followed by a \r\n then it is either... */
-			if (strncmp(boundary_end, "\r\n", 2))
-			{
+			if (strncmp(boundary_end, "\r\n", 2)) {
 				/* ...the final boundary, and it is followed by --, (in which
 				 * case it's the end of the request) or it's a malformed
 				 * request */

+ 3 - 3
src/mod_gnutls.inl

@@ -17,9 +17,9 @@ CIVETWEB_API int gtls_sslctx_init(SSL_CTX *ctx, const char *crt);
 CIVETWEB_API void gtls_sslctx_uninit(SSL_CTX *ctx);
 CIVETWEB_API void gtls_ssl_close(SSL *ssl);
 CIVETWEB_API int gtls_ssl_accept(SSL **ssl,
-                    SSL_CTX *ssl_ctx,
-                    int sock,
-                    struct mg_context *phys_ctx);
+                                 SSL_CTX *ssl_ctx,
+                                 int sock,
+                                 struct mg_context *phys_ctx);
 CIVETWEB_API int gtls_ssl_read(SSL *ssl, unsigned char *buf, size_t len);
 CIVETWEB_API int gtls_ssl_write(SSL *ssl, const unsigned char *buf, size_t len);
 

+ 13 - 11
src/mod_lua.inl

@@ -11,8 +11,7 @@
 #include "civetweb_private_lua.h"
 
 /* Prototypes */
-static int
-lua_error_handler(lua_State *L);
+static int lua_error_handler(lua_State *L);
 
 #if defined(_WIN32)
 static void *
@@ -648,14 +647,19 @@ run_lsp_kepler(struct mg_connection *conn,
 		/* Initialize a new HTTP response, either with some-predefined
 		 * status code (e.g. 404 if this is called from an error
 		 * handler) or with 200 OK */
-		mg_response_header_start(conn, conn->status_code > 0 ? conn->status_code : 200);
+		mg_response_header_start(conn,
+		                         conn->status_code > 0 ? conn->status_code
+		                                               : 200);
 
 		/* Add additional headers */
 		send_no_cache_header(conn);
 		send_additional_header(conn);
 
 		/* Add content type */
-		mg_response_header_add(conn, "Content-Type", "text/html; charset=utf-8", -1);
+		mg_response_header_add(conn,
+		                       "Content-Type",
+		                       "text/html; charset=utf-8",
+		                       -1);
 
 		/* Send the HTTP response (status and all headers) */
 		mg_response_header_send(conn);
@@ -679,8 +683,7 @@ run_lsp_kepler(struct mg_connection *conn,
 	} else {
 		/* Success loading chunk. Call it. */
 		lua_ok = lua_pcall(L, 0, 0, 0);
-		if(lua_ok != LUA_OK)
-		{
+		if (lua_ok != LUA_OK) {
 			lua_cry(conn, lua_ok, L, "LSP Kepler", "call");
 			lua_error_handler(L);
 			return 1;
@@ -804,8 +807,7 @@ run_lsp_civetweb(struct mg_connection *conn,
 					} else {
 						/* Success loading chunk. Call it. */
 						lua_ok = lua_pcall(L, 0, 0, 0);
-						if(lua_ok != LUA_OK)
-						{
+						if (lua_ok != LUA_OK) {
 							lua_cry(conn, lua_ok, L, "LSP", "call");
 							lua_error_handler(L);
 							return 1;
@@ -2801,7 +2803,7 @@ lua_error_handler(lua_State *L)
 		lua_pushstring(L, error_msg);
 		lua_pushliteral(L, "\n");
 		lua_call(L, 2, 0); /* call mg.write(error_msg + \n) */
-		lua_pop(L, 1); /* pop mg */
+		lua_pop(L, 1);     /* pop mg */
 
 		/* Get Lua traceback */
 		lua_getglobal(L, "debug");
@@ -2817,8 +2819,8 @@ lua_error_handler(lua_State *L)
 		/* Only print the traceback if it is not empty */
 		if (strcmp(lua_tostring(L, -1), "stack traceback:") != 0) {
 			lua_pushliteral(L, "\n"); /* append a newline */
-			lua_call(L, 2, 0); /* call mg.write(traceback + \n) */
-			lua_pop(L, 2); /* pop mg and traceback */
+			lua_call(L, 2, 0);        /* call mg.write(traceback + \n) */
+			lua_pop(L, 2);            /* pop mg and traceback */
 		} else {
 			lua_pop(L, 3); /* pop mg, traceback and error message */
 		}

+ 2 - 1
src/mod_mbedtls.inl

@@ -95,7 +95,8 @@ mbed_sslctx_init(SSL_CTX *ctx, const char *crt)
 	 */
 	const psa_status_t status = psa_crypto_init();
 	if (status != PSA_SUCCESS) {
-		DEBUG_TRACE("Failed to initialize PSA crypto, returned %d\n", (int) status);
+		DEBUG_TRACE("Failed to initialize PSA crypto, returned %d\n",
+		            (int)status);
 		return -1;
 	}
 #endif

+ 53 - 54
unittest/public_server.c

@@ -847,7 +847,7 @@ START_TEST(test_mg_server_and_client_tls)
 	 * while Ubuntu Xenial, Ubuntu Trusty and Windows test containers at
 	 * Travis CI do not. Maybe it is OpenSSL version specific.
 	 */
-#if defined(OPENSSL_API_1_1) || defined(OPENSSL_API_3_0) 
+#if defined(OPENSSL_API_1_1) || defined(OPENSSL_API_3_0)
 	if (client_conn) {
 		/* Connect succeeds, but the connection is unusable. */
 		mg_printf(client_conn, "GET / HTTP/1.0\r\n\r\n");
@@ -3091,7 +3091,7 @@ START_TEST(test_handle_form)
 
 	/* Handle form: "POST multipart/form-data" without trailing CRLF*/
 	multipart_body =
-		"--multipart-form-data-boundary--see-RFC-2388\r\n"
+	    "--multipart-form-data-boundary--see-RFC-2388\r\n"
 	    "Content-Disposition: form-data; name=\"textin\"\r\n"
 	    "\r\n"
 	    "text\r\n"
@@ -3629,11 +3629,11 @@ START_TEST(test_handle_form)
 	multipart_body =
 	    "--multipart-form-data-boundary--see-RFC-2388\r\n"
 	    "Content-Disposition: form-data; "
-		"custom1name=\"1\"; "
-		"custom2name=\"2\"; "
-		"custom3name=\"3\"; "
-		"custom4name=\"4\"; "
-		"name=\"textin\"\r\n"
+	    "custom1name=\"1\"; "
+	    "custom2name=\"2\"; "
+	    "custom3name=\"3\"; "
+	    "custom4name=\"4\"; "
+	    "name=\"textin\"\r\n"
 	    "\r\n"
 	    "text\r\n"
 	    "--multipart-form-data-boundary--see-RFC-2388\t\t\t\r\n"
@@ -3791,53 +3791,52 @@ START_TEST(test_handle_form)
 	mg_close_connection(client_conn);
 
 	/* Handle form: "POST multipart/form-data" very long preamble */
-	multipart_body =
-	    "preamblepreamblepreamblepreamblepreamble\r\n"
-	    "preamblepreamblepreamblepreamblepreamble\r\n"
-	    "preamblepreamblepreamblepreamblepreamble\r\n"
-	    "preamblepreamblepreamblepreamblepreamble\r\n"
-	    "preamblepreamblepreamblepreamblepreamble\r\n"
-	    "preamblepreamblepreamblepreamblepreamble\r\n"
-	    "preamblepreamblepreamblepreamblepreamble\r\n"
-	    "preamblepreamblepreamblepreamblepreamble\r\n"
-	    "preamblepreamblepreamblepreamblepreamble\r\n"
-	    "preamblepreamblepreamblepreamblepreamble\r\n"
-	    "preamblepreamblepreamblepreamblepreamble\r\n"
-	    "preamblepreamblepreamblepreamblepreamble\r\n"
-	    "preamblepreamblepreamblepreamblepreamble\r\n"
-	    "preamblepreamblepreamblepreamblepreamble\r\n"
-	    "preamblepreamblepreamblepreamblepreamble\r\n"
-	    "preamblepreamblepreamblepreamblepreamble\r\n"
-	    "preamblepreamblepreamblepreamblepreamble\r\n"
-	    "preamblepreamblepreamblepreamblepreamble\r\n"
-	    "preamblepreamblepreamblepreamblepreamble\r\n"
-	    "preamblepreamblepreamblepreamblepreamble\r\n"
-	    "preamblepreamblepreamblepreamblepreamble\r\n"
-	    "preamblepreamblepreamblepreamblepreamble\r\n"
-	    "preamblepreamblepreamblepreamblepreamble\r\n"
-	    "preamblepreamblepreamblepreamblepreamble\r\n"
-	    "preamblepreamblepreamblepreamblepreamble\r\n"
-	    "preamblepreamblepreamblepreamblepreamble\r\n"
-	    "preamblepreamblepreamblepreamblepreamble\r\n"
-	    "preamblepreamblepreamblepreamblepreamble\r\n"
-	    "preamblepreamblepreamblepreamblepreamble\r\n"
-	    "preamblepreamblepreamblepreamblepreamble\r\n"
-	    "preamblepreamblepreamblepreamblepreamble\r\n"
-	    "preamblepreamblepreamblepreamblepreamble\r\n"
-	    "preamblepreamblepreamblepreamblepreamble\r\n"
-	    "preamblepreamblepreamblepreamblepreamble\r\n"
-	    "preamblepreamblepreamblepreamblepreamble\r\n"
-	    "preamblepreamblepreamblepreamblepreamble\r\n"
-	    "preamblepreamblepreamblepreamblepreamble\r\n"
-	    "preamblepreamblepreamblepreamblepreamble\r\n"
-	    "preamblepreamblepreamblepreamblepreamble\r\n"
-	    "preamblepreamblepreamblepreamblepreamble\r\n"
-	    "preamblepreamblepreamblepreamblepreamble\r\n"
-	    "--multipart-form-data-boundary--see-RFC-2388\r\n";
-	    "Content-Disposition: form-data; name=\"passwordin\"\r\n"
-	    "\r\n"
-	    "\r\n"
-	    "--multipart-form-data-boundary--see-RFC-2388--\r\n";
+	multipart_body = "preamblepreamblepreamblepreamblepreamble\r\n"
+	                 "preamblepreamblepreamblepreamblepreamble\r\n"
+	                 "preamblepreamblepreamblepreamblepreamble\r\n"
+	                 "preamblepreamblepreamblepreamblepreamble\r\n"
+	                 "preamblepreamblepreamblepreamblepreamble\r\n"
+	                 "preamblepreamblepreamblepreamblepreamble\r\n"
+	                 "preamblepreamblepreamblepreamblepreamble\r\n"
+	                 "preamblepreamblepreamblepreamblepreamble\r\n"
+	                 "preamblepreamblepreamblepreamblepreamble\r\n"
+	                 "preamblepreamblepreamblepreamblepreamble\r\n"
+	                 "preamblepreamblepreamblepreamblepreamble\r\n"
+	                 "preamblepreamblepreamblepreamblepreamble\r\n"
+	                 "preamblepreamblepreamblepreamblepreamble\r\n"
+	                 "preamblepreamblepreamblepreamblepreamble\r\n"
+	                 "preamblepreamblepreamblepreamblepreamble\r\n"
+	                 "preamblepreamblepreamblepreamblepreamble\r\n"
+	                 "preamblepreamblepreamblepreamblepreamble\r\n"
+	                 "preamblepreamblepreamblepreamblepreamble\r\n"
+	                 "preamblepreamblepreamblepreamblepreamble\r\n"
+	                 "preamblepreamblepreamblepreamblepreamble\r\n"
+	                 "preamblepreamblepreamblepreamblepreamble\r\n"
+	                 "preamblepreamblepreamblepreamblepreamble\r\n"
+	                 "preamblepreamblepreamblepreamblepreamble\r\n"
+	                 "preamblepreamblepreamblepreamblepreamble\r\n"
+	                 "preamblepreamblepreamblepreamblepreamble\r\n"
+	                 "preamblepreamblepreamblepreamblepreamble\r\n"
+	                 "preamblepreamblepreamblepreamblepreamble\r\n"
+	                 "preamblepreamblepreamblepreamblepreamble\r\n"
+	                 "preamblepreamblepreamblepreamblepreamble\r\n"
+	                 "preamblepreamblepreamblepreamblepreamble\r\n"
+	                 "preamblepreamblepreamblepreamblepreamble\r\n"
+	                 "preamblepreamblepreamblepreamblepreamble\r\n"
+	                 "preamblepreamblepreamblepreamblepreamble\r\n"
+	                 "preamblepreamblepreamblepreamblepreamble\r\n"
+	                 "preamblepreamblepreamblepreamblepreamble\r\n"
+	                 "preamblepreamblepreamblepreamblepreamble\r\n"
+	                 "preamblepreamblepreamblepreamblepreamble\r\n"
+	                 "preamblepreamblepreamblepreamblepreamble\r\n"
+	                 "preamblepreamblepreamblepreamblepreamble\r\n"
+	                 "preamblepreamblepreamblepreamblepreamble\r\n"
+	                 "preamblepreamblepreamblepreamblepreamble\r\n"
+	                 "--multipart-form-data-boundary--see-RFC-2388\r\n";
+	"Content-Disposition: form-data; name=\"passwordin\"\r\n"
+	"\r\n"
+	"\r\n"
+	"--multipart-form-data-boundary--see-RFC-2388--\r\n";
 
 	body_len = strlen(multipart_body);
 	ck_assert_uint_eq(body_len, 1768); /* not required */