Skip to content

Commit 11654fd

Browse files
committed
Merge branch 'PHP-7.2' into PHP-7.3
* PHP-7.2: Fix #78641: addGlob can modify given remove_path value
2 parents 8a03fd6 + fd3118f commit 11654fd

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ PHP NEWS
4949
. Fixed bug #76859 (stream_get_line skips data if used with data-generating
5050
filter). (kkopachev)
5151

52+
- Zip:
53+
. Fixed bug #78641 (addGlob can modify given remove_path value). (cmb)
54+
5255
26 Sep 2019, PHP 7.3.10
5356

5457
- Core:

ext/zip/php_zip.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1670,7 +1670,7 @@ static void php_zip_add_from_pattern(INTERNAL_FUNCTION_PARAMETERS, int type) /*
16701670
struct zip *intern;
16711671
zval *self = getThis();
16721672
char *path = ".";
1673-
char *remove_path = NULL;
1673+
char *remove_path = NULL, *save_remove_path;
16741674
char *add_path = NULL;
16751675
size_t add_path_len, remove_path_len = 0, path_len = 1;
16761676
zend_long remove_all_path = 0;
@@ -1706,10 +1706,11 @@ static void php_zip_add_from_pattern(INTERNAL_FUNCTION_PARAMETERS, int type) /*
17061706
RETURN_FALSE;
17071707
}
17081708

1709+
save_remove_path = remove_path;
17091710
if (remove_path && remove_path_len > 1) {
17101711
size_t real_len = strlen(remove_path);
17111712
if ((real_len > 1) && ((remove_path[real_len - 1] == '/') || (remove_path[real_len - 1] == '\\'))) {
1712-
remove_path[real_len - 1] = '\0';
1713+
remove_path = estrndup(remove_path, real_len - 1);
17131714
}
17141715
}
17151716

@@ -1769,6 +1770,9 @@ static void php_zip_add_from_pattern(INTERNAL_FUNCTION_PARAMETERS, int type) /*
17691770
}
17701771
}
17711772
}
1773+
if (remove_path != save_remove_path) {
1774+
efree(remove_path);
1775+
}
17721776
}
17731777
/* }}} */
17741778

ext/zip/tests/bug78641.phpt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--TEST--
2+
Bug #78641 (addGlob can modify given remove_path value)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('zip')) die('skip zip extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
define("TMPDIR", __DIR__ . "/");
10+
11+
$file = TMPDIR . 'bug78641';
12+
touch($file);
13+
14+
$zip = new ZipArchive();
15+
$zip->open(TMPDIR . "bug78641.zip", ZipArchive::CREATE | ZipArchive::OVERWRITE);
16+
var_dump(basename(TMPDIR));
17+
$zip->addGlob($file, 0, ["remove_path" => TMPDIR]);
18+
var_dump(basename(TMPDIR));
19+
$zip->close();
20+
?>
21+
--EXPECT--
22+
string(5) "tests"
23+
string(5) "tests"
24+
--CLEAN--
25+
<?php
26+
unlink(__DIR__ . '/bug78641');
27+
unlink(__DIR__ . '/bug78641.zip');
28+
?>

0 commit comments

Comments
 (0)