mirror of
https://github.com/php/php-src.git
synced 2025-08-18 23:18:56 +02:00
- MFB: PECL #11216, addEmptyDir crashes if the directory already exists
This commit is contained in:
parent
6504c24187
commit
c4bff4d756
2 changed files with 59 additions and 3 deletions
|
@ -996,6 +996,9 @@ static ZIPARCHIVE_METHOD(addEmptyDir)
|
||||||
zval *this = getThis();
|
zval *this = getThis();
|
||||||
char *dirname;
|
char *dirname;
|
||||||
int dirname_len;
|
int dirname_len;
|
||||||
|
int idx;
|
||||||
|
struct zip_stat sb;
|
||||||
|
char *s;
|
||||||
|
|
||||||
if (!this) {
|
if (!this) {
|
||||||
RETURN_FALSE;
|
RETURN_FALSE;
|
||||||
|
@ -1007,14 +1010,39 @@ static ZIPARCHIVE_METHOD(addEmptyDir)
|
||||||
&dirname, &dirname_len, UG(ascii_conv)) == FAILURE) {
|
&dirname, &dirname_len, UG(ascii_conv)) == FAILURE) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dirname_len<1) {
|
if (dirname_len<1) {
|
||||||
RETURN_FALSE;
|
RETURN_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (zip_add_dir(intern, (const char *)dirname) < 0) {
|
if (dirname[dirname_len-1] != '/') {
|
||||||
RETURN_FALSE;
|
s=(char *)emalloc(dirname_len+2);
|
||||||
|
strcpy(s, dirname);
|
||||||
|
s[dirname_len] = '/';
|
||||||
|
s[dirname_len+1] = '\0';
|
||||||
|
} else {
|
||||||
|
s = dirname;
|
||||||
|
}
|
||||||
|
|
||||||
|
idx = zip_stat(intern, s, 0, &sb);
|
||||||
|
if (idx >= 0) {
|
||||||
|
RETVAL_FALSE;
|
||||||
|
} else {
|
||||||
|
/* reset the error */
|
||||||
|
if (intern->error.str) {
|
||||||
|
_zip_error_fini(&intern->error);
|
||||||
|
}
|
||||||
|
_zip_error_init(&intern->error);
|
||||||
|
|
||||||
|
if (zip_add_dir(intern, (const char *)s) == -1) {
|
||||||
|
RETVAL_FALSE;
|
||||||
|
}
|
||||||
|
RETVAL_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (s != dirname) {
|
||||||
|
efree(s);
|
||||||
}
|
}
|
||||||
RETURN_TRUE;
|
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
|
28
ext/zip/tests/bug11216.phpt
Normal file
28
ext/zip/tests/bug11216.phpt
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
--TEST--
|
||||||
|
Bug #11216 (::addEmptyDir() crashes when the directory already exists)
|
||||||
|
--SKIPIF--
|
||||||
|
<?php
|
||||||
|
/* $Id$ */
|
||||||
|
if(!extension_loaded('zip')) die('skip');
|
||||||
|
?>
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
$archive = new ZipArchive();
|
||||||
|
$archive->open('__test.zip', ZIPARCHIVE::CREATE);
|
||||||
|
var_dump($archive->addEmptyDir('test'));
|
||||||
|
print_r($archive);
|
||||||
|
var_dump($archive->addEmptyDir('test'));
|
||||||
|
$archive->close();
|
||||||
|
unlink('__test.zip');
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
bool(true)
|
||||||
|
ZipArchive Object
|
||||||
|
(
|
||||||
|
[status] => 0
|
||||||
|
[statusSys] => 0
|
||||||
|
[numFiles] => 1
|
||||||
|
[filename] =>
|
||||||
|
[comment] =>
|
||||||
|
)
|
||||||
|
bool(false)
|
Loading…
Add table
Add a link
Reference in a new issue