Skip to content

Commit a67f351

Browse files
committedMar 16, 2025
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3: Fix GH-18082: Memory leaks in fuzzer SAPI error paths
2 parents 45fc03c + 38e553e commit a67f351

File tree

5 files changed

+22
-17
lines changed

5 files changed

+22
-17
lines changed
 

‎NEWS

+4
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ PHP NEWS
3636
. Fixed bug GH-17991 (Assertion failure dom_attr_value_write). (nielsdos)
3737
. Fix weird unpack behaviour in DOM. (nielsdos)
3838

39+
- Fuzzer:
40+
. Fixed bug GH-18081 (Memory leaks in error paths of fuzzer SAPI).
41+
(Lung-Alexandra)
42+
3943
- GD:
4044
. Fixed bug GH-17984 (calls with arguments as array with references).
4145
(David Carlier)

‎sapi/fuzzer/fuzzer-json.c

+5-6
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
+----------------------------------------------------------------------+
1616
*/
1717

18-
19-
2018
#include "fuzzer.h"
2119

2220
#include "Zend/zend.h"
@@ -31,14 +29,15 @@
3129
#include "ext/json/php_json_parser.h"
3230

3331
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
34-
char *data = malloc(Size+1);
35-
memcpy(data, Data, Size);
36-
data[Size] = '\0';
3732

38-
if (fuzzer_request_startup() == FAILURE) {
33+
if (fuzzer_request_startup() == FAILURE){
3934
return 0;
4035
}
4136

37+
char *data = malloc(Size + 1);
38+
memcpy(data, Data, Size);
39+
data[Size] = '\0';
40+
4241
for (int option = 0; option <=1; ++option) {
4342
zval result;
4443
php_json_parser parser;

‎sapi/fuzzer/fuzzer-mbregex.c

+5-4
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,16 @@
3030

3131
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
3232
#ifdef HAVE_MBREGEX
33-
char *args[2];
34-
char *data = malloc(Size+1);
35-
memcpy(data, Data, Size);
36-
data[Size] = '\0';
3733

3834
if (fuzzer_request_startup() == FAILURE) {
3935
return 0;
4036
}
4137

38+
char *args[2];
39+
char *data = malloc(Size+1);
40+
memcpy(data, Data, Size);
41+
data[Size] = '\0';
42+
4243
fuzzer_setup_dummy_frame();
4344

4445
args[0] = data;

‎sapi/fuzzer/fuzzer-unserialize.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,15 @@
3030
#include "ext/standard/php_var.h"
3131

3232
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
33-
unsigned char *orig_data = malloc(Size+1);
34-
memcpy(orig_data, Data, Size);
35-
orig_data[Size] = '\0';
3633

3734
if (fuzzer_request_startup() == FAILURE) {
3835
return 0;
3936
}
4037

38+
unsigned char *orig_data = malloc(Size+1);
39+
memcpy(orig_data, Data, Size);
40+
orig_data[Size] = '\0';
41+
4142
fuzzer_setup_dummy_frame();
4243

4344
{

‎sapi/fuzzer/fuzzer-unserializehash.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t FullSize) {
3434
}
3535
++Start;
3636

37+
if (fuzzer_request_startup() == FAILURE) {
38+
return 0;
39+
}
40+
3741
size_t Size = (Data + FullSize) - Start;
3842
unsigned char *orig_data = malloc(Size+1);
3943
memcpy(orig_data, Start, Size);
4044
orig_data[Size] = '\0';
4145

42-
if (fuzzer_request_startup() == FAILURE) {
43-
return 0;
44-
}
45-
4646
fuzzer_setup_dummy_frame();
4747

4848
{

0 commit comments

Comments
 (0)
Failed to load comments.