summaryrefslogtreecommitdiff
path: root/ext/zip
diff options
context:
space:
mode:
authorPierre Joye <pajoye@php.net>2007-06-03 19:47:17 +0000
committerPierre Joye <pajoye@php.net>2007-06-03 19:47:17 +0000
commitef952b0383745f4543007076080b85829367018e (patch)
tree807845aafad60d5fff940be55d7ca9300ab1e9b4 /ext/zip
parent029b4678aa9fc735d54d30db198439867c09de31 (diff)
downloadphp-git-ef952b0383745f4543007076080b85829367018e.tar.gz
- PECL #11216, addEmptyDir crashes if the directory already exists
Diffstat (limited to 'ext/zip')
-rw-r--r--ext/zip/php_zip.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/ext/zip/php_zip.c b/ext/zip/php_zip.c
index c1ab3cc507..5f56478949 100644
--- a/ext/zip/php_zip.c
+++ b/ext/zip/php_zip.c
@@ -985,6 +985,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;
@@ -996,13 +999,30 @@ static ZIPARCHIVE_METHOD(addEmptyDir)
&dirname, &dirname_len) == FAILURE) {
return;
}
+
if (dirname_len<1) {
RETURN_FALSE;
}
- if (zip_add_dir(intern, (const char *)dirname) < 0) {
+ 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) {
+ RETURN_FALSE;
+ }
+
+ if (zip_add_dir(intern, (const char *)s) == -1) {
RETURN_FALSE;
}
+
RETURN_TRUE;
}
/* }}} */