diff options
| author | Pierre Joye <pajoye@php.net> | 2006-08-13 21:09:59 +0000 |
|---|---|---|
| committer | Pierre Joye <pajoye@php.net> | 2006-08-13 21:09:59 +0000 |
| commit | 8d07735332892b44880d701ffe6f8e119181dd8d (patch) | |
| tree | be23ba4c3c01548566fbefbfa383ca4e0a79dae3 /ext/zip/lib | |
| parent | 0587fb32ba65012aee28c6167900c9930256667b (diff) | |
| download | php-git-8d07735332892b44880d701ffe6f8e119181dd8d.tar.gz | |
- MFP:
- add overwrite mode to ZipArchive::open, always starts a new archive
- Fix safe mode checks on extract
- Fix possible leaks when a safe mode error has been raised
Diffstat (limited to 'ext/zip/lib')
| -rw-r--r-- | ext/zip/lib/zip.h | 1 | ||||
| -rw-r--r-- | ext/zip/lib/zip_open.c | 19 | ||||
| -rw-r--r-- | ext/zip/lib/zip_replace.c | 5 |
3 files changed, 15 insertions, 10 deletions
diff --git a/ext/zip/lib/zip.h b/ext/zip/lib/zip.h index 93c791f14c..8cf690cad3 100644 --- a/ext/zip/lib/zip.h +++ b/ext/zip/lib/zip.h @@ -53,6 +53,7 @@ extern "C" { #define ZIP_CREATE 1 #define ZIP_EXCL 2 #define ZIP_CHECKCONS 4 +#define ZIP_OVERWRITE 8 /* flags for zip_name_locate, zip_fopen, zip_stat, ... */ diff --git a/ext/zip/lib/zip_open.c b/ext/zip/lib/zip_open.c index 65ba8a5b9f..0a14abda58 100644 --- a/ext/zip/lib/zip_open.c +++ b/ext/zip/lib/zip_open.c @@ -74,9 +74,9 @@ zip_open(const char *fn, int flags, int *zep) set_error(zep, NULL, ZIP_ER_INVAL); return NULL; } - - if (stat(fn, &st) != 0) { - if (flags & ZIP_CREATE) { + + if (flags & ZIP_OVERWRITE || stat(fn, &st) != 0) { + if ((flags & ZIP_CREATE) || (flags & ZIP_OVERWRITE)) { if ((za=_zip_new(&error)) == NULL) { set_error(zep, &error, 0); return NULL; @@ -99,14 +99,15 @@ zip_open(const char *fn, int flags, int *zep) set_error(zep, NULL, ZIP_ER_EXISTS); return NULL; } + + /* ZIP_CREATE gets ignored if file exists and not ZIP_EXCL, just like open() */ - - if ((fp=fopen(fn, "rb")) == NULL) { - set_error(zep, NULL, ZIP_ER_OPEN); - return NULL; - } - + if ((fp=fopen(fn, "rb")) == NULL) { + set_error(zep, NULL, ZIP_ER_OPEN); + return NULL; + } + clearerr(fp); fseek(fp, 0, SEEK_END); len = ftell(fp); diff --git a/ext/zip/lib/zip_replace.c b/ext/zip/lib/zip_replace.c index 011bbc2af0..ae78e62b80 100644 --- a/ext/zip/lib/zip_replace.c +++ b/ext/zip/lib/zip_replace.c @@ -66,11 +66,14 @@ _zip_replace(struct zip *za, int idx, const char *name, return -1; idx = za->nentry - 1; } - + + _zip_unchange_data(za->entry+idx); if (name && _zip_set_name(za, idx, name) != 0) return -1; + + za->entry[idx].state = ((za->cdir == NULL || idx >= za->cdir->nentry) ? ZIP_ST_ADDED : ZIP_ST_REPLACED); za->entry[idx].source = source; |
