- MFB: PECL #11216, addEmptyDir crashes if the directory already exists

This commit is contained in:
Pierre Joye 2007-06-03 21:30:12 +00:00
parent 6504c24187
commit c4bff4d756
2 changed files with 59 additions and 3 deletions

View file

@ -996,6 +996,9 @@ static ZIPARCHIVE_METHOD(addEmptyDir)
zval *this = getThis();
char *dirname;
int dirname_len;
int idx;
struct zip_stat sb;
char *s;
if (!this) {
RETURN_FALSE;
@ -1007,14 +1010,39 @@ static ZIPARCHIVE_METHOD(addEmptyDir)
&dirname, &dirname_len, UG(ascii_conv)) == FAILURE) {
return;
}
if (dirname_len<1) {
RETURN_FALSE;
}
if (zip_add_dir(intern, (const char *)dirname) < 0) {
RETURN_FALSE;
if (dirname[dirname_len-1] != '/') {
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;
}
/* }}} */

View 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)