Skip to content

Commit d9f57e8

Browse files
committed
Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3: Fixed bug #78910 Fix #78878: Buffer underflow in bc_shift_addsub Fix test Fix #78862: link() silently truncates after a null byte on Windows Fix #78863: DirectoryIterator class silently truncates after a null byte Fix #78943: mail() may release string with refcount==1 twice
2 parents 7e9e093 + a65b8ab commit d9f57e8

File tree

9 files changed

+87
-9
lines changed

9 files changed

+87
-9
lines changed

ext/bcmath/libbcmath/src/str2num.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ bc_str2num (bc_num *num, char *str, int scale)
5656
zero_int = FALSE;
5757
if ( (*ptr == '+') || (*ptr == '-')) ptr++; /* Sign */
5858
while (*ptr == '0') ptr++; /* Skip leading zeros. */
59-
while (isdigit((int)*ptr)) ptr++, digits++; /* digits */
59+
while (*ptr >= '0' && *ptr <= '9') ptr++, digits++; /* digits */
6060
if (*ptr == '.') ptr++; /* decimal point */
61-
while (isdigit((int)*ptr)) ptr++, strscale++; /* digits */
61+
while (*ptr >= '0' && *ptr <= '9') ptr++, strscale++; /* digits */
6262
if ((*ptr != '\0') || (digits+strscale == 0))
6363
{
6464
*num = bc_copy_num (BCG(_zero_));

ext/bcmath/tests/bug78878.phpt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
Bug #78878 (Buffer underflow in bc_shift_addsub)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('bcmath')) die('skip bcmath extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
print @bcmul("\xB26483605105519922841849335928742092", bcpowmod(2, 65535, -4e-4));
10+
?>
11+
--EXPECT--
12+
bc math warning: non-zero scale in modulus
13+
0

ext/exif/exif.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3129,7 +3129,10 @@ static int exif_process_IFD_in_MAKERNOTE(image_info_type *ImageInfo, char * valu
31293129
/*exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, "check (%s)", maker_note->make?maker_note->make:"");*/
31303130
if (maker_note->make && (!ImageInfo->make || strcmp(maker_note->make, ImageInfo->make)))
31313131
continue;
3132-
if (maker_note->id_string && strncmp(maker_note->id_string, value_ptr, maker_note->id_string_len))
3132+
if (maker_note->model && (!ImageInfo->model || strcmp(maker_note->model, ImageInfo->model)))
3133+
continue;
3134+
if (maker_note->id_string && value_len >= maker_note->id_string_len
3135+
&& strncmp(maker_note->id_string, value_ptr, maker_note->id_string_len))
31333136
continue;
31343137
break;
31353138
}

ext/exif/tests/bug78910.phpt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
Bug #78910: Heap-buffer-overflow READ in exif (OSS-Fuzz #19044)
3+
--FILE--
4+
<?php
5+
6+
var_dump(exif_read_data('data:image/jpg;base64,TU0AKgAAAAwgICAgAAIBDwAEAAAAAgAAACKSfCAgAAAAAEZVSklGSUxN'));
7+
8+
?>
9+
--EXPECTF--
10+
Notice: exif_read_data(): Read from TIFF: tag(0x927C, MakerNote ): Illegal format code 0x2020, switching to BYTE in %s on line %d
11+
12+
Warning: exif_read_data(): Process tag(x927C=MakerNote ): Illegal format code 0x2020, suppose BYTE in %s on line %d
13+
14+
Warning: exif_read_data(): IFD data too short: 0x0000 offset 0x000C in %s on line %d
15+
16+
Warning: exif_read_data(): Invalid TIFF file in %s on line %d
17+
bool(false)

ext/spl/spl_directory.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -708,10 +708,10 @@ void spl_filesystem_object_construct(INTERNAL_FUNCTION_PARAMETERS, zend_long cto
708708

709709
if (SPL_HAS_FLAG(ctor_flags, DIT_CTOR_FLAGS)) {
710710
flags = SPL_FILE_DIR_KEY_AS_PATHNAME|SPL_FILE_DIR_CURRENT_AS_FILEINFO;
711-
parsed = zend_parse_parameters(ZEND_NUM_ARGS(), "s|l", &path, &len, &flags);
711+
parsed = zend_parse_parameters(ZEND_NUM_ARGS(), "p|l", &path, &len, &flags);
712712
} else {
713713
flags = SPL_FILE_DIR_KEY_AS_PATHNAME|SPL_FILE_DIR_CURRENT_AS_SELF;
714-
parsed = zend_parse_parameters(ZEND_NUM_ARGS(), "s", &path, &len);
714+
parsed = zend_parse_parameters(ZEND_NUM_ARGS(), "p", &path, &len);
715715
}
716716
if (SPL_HAS_FLAG(ctor_flags, SPL_FILE_DIR_SKIPDOTS)) {
717717
flags |= SPL_FILE_DIR_SKIPDOTS;

ext/spl/tests/bug54291.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Bug #54291 (Crash iterating DirectoryIterator for dir name starting with \0)
55
$dir = new DirectoryIterator("\x00/abc");
66
$dir->isFile();
77
--EXPECTF--
8-
Fatal error: Uncaught UnexpectedValueException: Failed to open directory "" in %s:%d
8+
Fatal error: Uncaught UnexpectedValueException: DirectoryIterator::__construct() expects parameter 1 to be a valid path, string given in %s:%d
99
Stack trace:
1010
#0 %s(%d): DirectoryIterator->__construct('\x00/abc')
1111
#1 {main}

ext/spl/tests/bug78863.phpt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
Bug #78863 (DirectoryIterator class silently truncates after a null byte)
3+
--FILE--
4+
<?php
5+
$dir = __DIR__ . '/bug78863';
6+
mkdir($dir);
7+
touch("$dir/bad");
8+
mkdir("$dir/sub");
9+
touch("$dir/sub/good");
10+
11+
$it = new DirectoryIterator(__DIR__ . "/bug78863\0/sub");
12+
foreach ($it as $fileinfo) {
13+
if (!$fileinfo->isDot()) {
14+
var_dump($fileinfo->getFilename());
15+
}
16+
}
17+
?>
18+
--EXPECTF--
19+
Fatal error: Uncaught UnexpectedValueException: DirectoryIterator::__construct() expects parameter 1 to be a valid path, string given in %s:%d
20+
Stack trace:
21+
#0 %s(%d): DirectoryIterator->__construct('%s')
22+
#1 {main}
23+
thrown in %s on line %d
24+
--CLEAN--
25+
<?php
26+
$dir = __DIR__ . '/bug78863';
27+
unlink("$dir/sub/good");
28+
rmdir("$dir/sub");
29+
unlink("$dir/bad");
30+
rmdir($dir);
31+
?>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
Bug #78862 (link() silently truncates after a null byte on Windows)
3+
--FILE--
4+
<?php
5+
file_put_contents(__DIR__ . '/bug78862.target', 'foo');
6+
var_dump(link(__DIR__ . "/bug78862.target\0more", __DIR__ . "/bug78862.link\0more"));
7+
var_dump(file_exists(__DIR__ . '/bug78862.link'));
8+
?>
9+
--EXPECTF--
10+
Warning: link() expects parameter 1 to be a valid path, string given in %s on line %d
11+
NULL
12+
bool(false)
13+
--CLEAN--
14+
<?php
15+
unlink(__DIR__ . '/bug78862.target');
16+
unlink(__DIR__ . '/bug78862.link');
17+
?>

win32/sendmail.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,6 @@ PHPAPI int TSendMail(char *host, int *error, char **error_message,
207207
/* Create a lowercased header for all the searches so we're finally case
208208
* insensitive when searching for a pattern. */
209209
headers_lc = zend_string_tolower(headers_trim);
210-
if (headers_lc == headers_trim) {
211-
zend_string_release_ex(headers_lc, 0);
212-
}
213210
}
214211

215212
/* Fall back to sendmail_from php.ini setting */

0 commit comments

Comments
 (0)