[prev in list] [next in list] [prev in thread] [next in thread] 

List:       php-cvs
Subject:    [PHP-CVS] [php-src] master: Clarify memory usage and slightly improve sapi_read_post_data
From:       Jakub Zelenka <noreply () php ! net>
Date:       2022-09-30 10:52:15
Message-ID: SKAysGqorDNQgqdwYfJW4vhu2e366X97OPIWOdb0s () main ! php ! net
[Download RAW message or body]

Author: Jakub Zelenka (bukka)
Date: 2022-09-30T11:54:41+01:00

Commit: https://github.com/php/php-src/commit/d2288ec5ed0a5a668d92497f4b4216fd549ad6fc
Raw diff: https://github.com/php/php-src/commit/d2288ec5ed0a5a668d92497f4b4216fd549ad6fc.diff

Clarify memory usage and slightly improve sapi_read_post_data

This is a result of checking GH-8800 which assumed potential
memory leaks here. Even though it was not the case in reality,
the function deserves a bit of clarification to prevent similar
attempts in the future.

Changed paths:
  M  main/SAPI.c


Diff:

diff --git a/main/SAPI.c b/main/SAPI.c
index 09b028e55166..019de09782de 100644
--- a/main/SAPI.c
+++ b/main/SAPI.c
@@ -183,7 +183,7 @@ static void sapi_read_post_data(void)
 	 * - Make the content type lowercase
 	 * - Trim descriptive data, stay with the content-type only
 	 */
-	for (p=content_type; p<content_type+content_type_length; p++) {
+	for (p = content_type; p < content_type + content_type_length; p++) {
 		switch (*p) {
 			case ';':
 			case ',':
@@ -207,10 +207,11 @@ static void sapi_read_post_data(void)
 	} else {
 		/* fallback */
 		SG(request_info).post_entry = NULL;
-		if (!sapi_module.default_post_reader) {
-			/* no default reader? */
+		if (UNEXPECTED(!sapi_module.default_post_reader)) {
+			/* this should not happen as there should always be a default_post_reader */
 			SG(request_info).content_type_dup = NULL;
 			sapi_module.sapi_error(E_WARNING, "Unsupported content type:  '%s'", content_type);
+			efree(content_type);
 			return;
 		}
 	}
@@ -218,6 +219,7 @@ static void sapi_read_post_data(void)
 		*(p-1) = oldchar;
 	}
 
+	/* the content_type_dup is not set at this stage so no need to try to free it first */
 	SG(request_info).content_type_dup = content_type;
 
 	if(post_reader_func) {

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic