Skip to content

Commit cecf734

Browse files
committed
Fixed bug #75774 imap_append HeapCorruction
1 parent 9d2662e commit cecf734

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

ext/imap/php_imap.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,18 +1312,18 @@ PHP_FUNCTION(imap_append)
13121312
zend_string *folder, *message, *internal_date = NULL, *flags = NULL;
13131313
pils *imap_le_struct;
13141314
STRING st;
1315-
zend_string* regex;
1316-
pcre_cache_entry *pce; /* Compiled regex */
1317-
zval *subpats = NULL; /* Parts (not used) */
1318-
int global = 0;
13191315

13201316
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rSS|SS", &streamind, &folder, &message, &flags, &internal_date) == FAILURE) {
13211317
return;
13221318
}
13231319

1324-
regex = zend_string_init("/[0-3][0-9]-((Jan)|(Feb)|(Mar)|(Apr)|(May)|(Jun)|(Jul)|(Aug)|(Sep)|(Oct)|(Nov)|(Dec))-[0-9]{4} [0-2][0-9]:[0-5][0-9]:[0-5][0-9] [+-][0-9]{4}/", sizeof("/[0-3][0-9]-((Jan)|(Feb)|(Mar)|(Apr)|(May)|(Jun)|(Jul)|(Aug)|(Sep)|(Oct)|(Nov)|(Dec))-[0-9]{4} [0-2][0-9]:[0-5][0-9]:[0-5][0-9] [+-][0-9]{4}/") - 1, 0);
13251320

13261321
if (internal_date) {
1322+
zend_string *regex = zend_string_init("/[0-3][0-9]-((Jan)|(Feb)|(Mar)|(Apr)|(May)|(Jun)|(Jul)|(Aug)|(Sep)|(Oct)|(Nov)|(Dec))-[0-9]{4} [0-2][0-9]:[0-5][0-9]:[0-5][0-9] [+-][0-9]{4}/", sizeof("/[0-3][0-9]-((Jan)|(Feb)|(Mar)|(Apr)|(May)|(Jun)|(Jul)|(Aug)|(Sep)|(Oct)|(Nov)|(Dec))-[0-9]{4} [0-2][0-9]:[0-5][0-9]:[0-5][0-9] [+-][0-9]{4}/") - 1, 0);
1323+
pcre_cache_entry *pce; /* Compiled regex */
1324+
zval *subpats = NULL; /* Parts (not used) */
1325+
int global = 0;
1326+
13271327
/* Make sure the given internal_date string matches the RFC specifiedformat */
13281328
if ((pce = pcre_get_compiled_regex_cache(regex))== NULL) {
13291329
zend_string_free(regex);
@@ -1340,7 +1340,6 @@ PHP_FUNCTION(imap_append)
13401340
}
13411341
}
13421342

1343-
zend_string_free(regex);
13441343
if ((imap_le_struct = (pils *)zend_fetch_resource(Z_RES_P(streamind), "imap", le_imap)) == NULL) {
13451344
RETURN_FALSE;
13461345
}

ext/imap/tests/bug75774.phpt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
Bug #75774 imap_append HeapCorruction
3+
--SKIPIF--
4+
<?php
5+
extension_loaded('imap') or die('skip imap extension not available in this build');
6+
?>
7+
--FILE--
8+
<?php
9+
10+
$fn = __DIR__ . DIRECTORY_SEPARATOR . "foo75774";
11+
$var1=fopen($fn, "w");
12+
13+
imap_append($var1, "", "", "", "");
14+
15+
fclose($var1);
16+
unlink($fn);
17+
18+
?>
19+
==DONE==
20+
--EXPECTF--
21+
Warning: imap_append(): internal date not correctly formatted in %s on line %d
22+
23+
Warning: imap_append(): supplied resource is not a valid imap resource in %s on line %d
24+
==DONE==

0 commit comments

Comments
 (0)