Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ext/zip/php_zip.c
Original file line number Diff line number Diff line change
Expand Up @@ -675,12 +675,14 @@ int php_zip_glob(char *pattern, int pattern_len, zend_long flags, zval *return_v

/* now catch the FreeBSD style of "no matches" */
if (!globbuf.gl_pathc || !globbuf.gl_pathv) {
globfree(&globbuf);
return 0;
}

/* we assume that any glob pattern will match files from one directory only
so checking the dirname of the first match should be sufficient */
if (ZIP_OPENBASEDIR_CHECKPATH(globbuf.gl_pathv[0])) {
globfree(&globbuf);
return -1;
}

Expand Down
21 changes: 21 additions & 0 deletions ext/zip/tests/gh21698.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--TEST--
GH-21698 (ZipArchive::addGlob memory leak when open_basedir rejects the match)
--EXTENSIONS--
zip
--FILE--
<?php
$zipfile = __DIR__ . '/gh21698.zip';
$zip = new ZipArchive();
$zip->open($zipfile, ZipArchive::CREATE | ZipArchive::OVERWRITE);

ini_set('open_basedir', '/nonexistent_dir_for_gh21698');
var_dump($zip->addGlob(__FILE__, 0, []));
$zip->close();
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/gh21698.zip');
?>
--EXPECTF--
Warning: ZipArchive::addGlob(): open_basedir restriction in effect. File(%s) is not within the allowed path(s): (%s) in %s on line %d
bool(false)
Loading