1 |
diff -up libzip-0.10/lib/zip_close.c.php libzip-0.10/lib/zip_close.c |
2 |
--- libzip-0.10/lib/zip_close.c.php 2011-02-20 09:01:03.000000000 -0500 |
3 |
+++ libzip-0.10/lib/zip_close.c 2012-01-25 18:37:04.188136374 -0500 |
4 |
@@ -602,13 +602,15 @@ _zip_create_temp_output(struct zip *za, |
5 |
char *temp; |
6 |
int tfd; |
7 |
FILE *tfp; |
8 |
+ |
9 |
+ int len = strlen(za->zn) + 8; |
10 |
|
11 |
- if ((temp=(char *)malloc(strlen(za->zn)+8)) == NULL) { |
12 |
+ if ((temp=(char *)malloc(len)) == NULL) { |
13 |
_zip_error_set(&za->error, ZIP_ER_MEMORY, 0); |
14 |
return NULL; |
15 |
} |
16 |
|
17 |
- sprintf(temp, "%s.XXXXXX", za->zn); |
18 |
+ snprintf(temp, len, "%s.XXXXXX", za->zn); |
19 |
|
20 |
if ((tfd=mkstemp(temp)) == -1) { |
21 |
_zip_error_set(&za->error, ZIP_ER_TMPOPEN, errno); |
22 |
diff -up libzip-0.10/lib/zip_fclose.c.php libzip-0.10/lib/zip_fclose.c |
23 |
--- libzip-0.10/lib/zip_fclose.c.php 2010-03-08 07:27:48.000000000 -0500 |
24 |
+++ libzip-0.10/lib/zip_fclose.c 2012-01-25 18:36:22.389542215 -0500 |
25 |
@@ -47,12 +47,14 @@ zip_fclose(struct zip_file *zf) |
26 |
if (zf->src) |
27 |
zip_source_free(zf->src); |
28 |
|
29 |
- for (i=0; i<zf->za->nfile; i++) { |
30 |
- if (zf->za->file[i] == zf) { |
31 |
- zf->za->file[i] = zf->za->file[zf->za->nfile-1]; |
32 |
- zf->za->nfile--; |
33 |
- break; |
34 |
- } |
35 |
+ if (zf->za) { |
36 |
+ for (i=0; i<zf->za->nfile; i++) { |
37 |
+ if (zf->za->file[i] == zf) { |
38 |
+ zf->za->file[i] = zf->za->file[zf->za->nfile-1]; |
39 |
+ zf->za->nfile--; |
40 |
+ break; |
41 |
+ } |
42 |
+ } |
43 |
} |
44 |
|
45 |
ret = 0; |
46 |
diff -up libzip-0.10/lib/zip.h.php libzip-0.10/lib/zip.h |
47 |
--- libzip-0.10/lib/zip.h.php 2011-03-04 12:17:43.000000000 -0500 |
48 |
+++ libzip-0.10/lib/zip.h 2012-01-25 18:36:22.389542215 -0500 |
49 |
@@ -59,7 +59,7 @@ extern "C" { |
50 |
#define ZIP_CREATE 1 |
51 |
#define ZIP_EXCL 2 |
52 |
#define ZIP_CHECKCONS 4 |
53 |
- |
54 |
+#define ZIP_OVERWRITE 8 |
55 |
|
56 |
/* flags for zip_name_locate, zip_fopen, zip_stat, ... */ |
57 |
|
58 |
diff -up libzip-0.10/lib/zip_open.c.php libzip-0.10/lib/zip_open.c |
59 |
--- libzip-0.10/lib/zip_open.c.php 2011-03-16 07:18:44.000000000 -0400 |
60 |
+++ libzip-0.10/lib/zip_open.c 2012-01-25 18:36:22.389542215 -0500 |
61 |
@@ -61,10 +61,16 @@ ZIP_EXTERN struct zip * |
62 |
zip_open(const char *fn, int flags, int *zep) |
63 |
{ |
64 |
FILE *fp; |
65 |
+ |
66 |
+ if (flags & ZIP_OVERWRITE) { |
67 |
+ return _zip_allocate_new(fn, zep); |
68 |
+ } |
69 |
|
70 |
switch (_zip_file_exists(fn, flags, zep)) { |
71 |
case -1: |
72 |
- return NULL; |
73 |
+ if (!(flags & ZIP_OVERWRITE)) { |
74 |
+ return NULL; |
75 |
+ } |
76 |
case 0: |
77 |
return _zip_allocate_new(fn, zep); |
78 |
default: |
79 |
@@ -482,7 +488,7 @@ _zip_file_exists(const char *fn, int fla |
80 |
} |
81 |
|
82 |
if (stat(fn, &st) != 0) { |
83 |
- if (flags & ZIP_CREATE) |
84 |
+ if (flags & ZIP_CREATE || flags & ZIP_OVERWRITE) |
85 |
return 0; |
86 |
else { |
87 |
set_error(zep, NULL, ZIP_ER_OPEN); |