]> granicus.if.org Git - php/commitdiff
- PECL #11216, addEmptyDir crashes if the directory already exists
authorPierre Joye <pajoye@php.net>
Sun, 3 Jun 2007 19:47:17 +0000 (19:47 +0000)
committerPierre Joye <pajoye@php.net>
Sun, 3 Jun 2007 19:47:17 +0000 (19:47 +0000)
ext/zip/php_zip.c

index c1ab3cc507337b57d92b52186063f61c4d4fbb83..5f56478949327475095ad7c76334a8af978e60a1 100644 (file)
@@ -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;
 }
 /* }}} */