From: Pierre Joye Date: Sun, 3 Jun 2007 19:47:17 +0000 (+0000) Subject: - PECL #11216, addEmptyDir crashes if the directory already exists X-Git-Tag: php-5.2.4RC1~444 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ef952b0383745f4543007076080b85829367018e;p=php - PECL #11216, addEmptyDir crashes if the directory already exists --- 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; } /* }}} */