git-svn: trunk@17
Tomasz Kojm authored on 2003/08/06 12:05:51... | ... |
@@ -1,6 +1,14 @@ |
1 |
+Wed Aug 6 03:01:51 CEST 2003 |
|
2 |
+----------------------------- |
|
3 |
+ * clamd: new directives: VirusAction, Debug |
|
4 |
+ * libclamav: zziplib downgraded to the old version due to Zip handling |
|
5 |
+ problems |
|
6 |
+ |
|
1 | 7 |
Sun Aug 3 03:35:49 CEST 2003 |
2 | 8 |
----------------------------- |
3 | 9 |
* libclamav: zziplib updated to 0.10.83-pre1 |
10 |
+ * clamscan: --debug enables libclamav's debug messages without a need |
|
11 |
+ to recompile with --enable-debug |
|
4 | 12 |
|
5 | 13 |
Sat Jul 26 17:11:46 CEST 2003 |
6 | 14 |
----------------------------- |
... | ... |
@@ -68,7 +68,7 @@ dnl there is now a CREATE_PREFIX_TARGET_H in this file as a shorthand for |
68 | 68 |
dnl PREFIX_CONFIG_H from a target.h file, however w/o the target.h ever created |
69 | 69 |
dnl (the prefix is a bit different, since we add an extra -target- and -host-) |
70 | 70 |
dnl |
71 |
-dnl @version: $Id: acinclude.m4,v 1.3 2003/08/03 22:25:30 kojm Exp $ |
|
71 |
+dnl @version: $Id: acinclude.m4,v 1.4 2003/08/06 03:05:50 kojm Exp $ |
|
72 | 72 |
dnl @author Guido Draheim <guidod@gmx.de> STATUS: used often |
73 | 73 |
|
74 | 74 |
AC_DEFUN([AC_CREATE_TARGET_H], |
... | ... |
@@ -4110,7 +4110,7 @@ dnl AC_COMPILE_CHECK_SIZEOF(ptrdiff_t, $headers) |
4110 | 4110 |
dnl AC_COMPILE_CHECK_SIZEOF(off_t, $headers) |
4111 | 4111 |
dnl |
4112 | 4112 |
dnl @author Kaveh Ghazi <ghazi@caip.rutgers.edu> |
4113 |
-dnl @version $Id: acinclude.m4,v 1.3 2003/08/03 22:25:30 kojm Exp $ |
|
4113 |
+dnl @version $Id: acinclude.m4,v 1.4 2003/08/06 03:05:50 kojm Exp $ |
|
4114 | 4114 |
dnl |
4115 | 4115 |
AC_DEFUN([AC_COMPILE_CHECK_SIZEOF], |
4116 | 4116 |
[changequote(<<, >>)dnl |
... | ... |
@@ -81,7 +81,7 @@ dnl there is now a CREATE_PREFIX_TARGET_H in this file as a shorthand for |
81 | 81 |
dnl PREFIX_CONFIG_H from a target.h file, however w/o the target.h ever created |
82 | 82 |
dnl (the prefix is a bit different, since we add an extra -target- and -host-) |
83 | 83 |
dnl |
84 |
-dnl @version: $Id: aclocal.m4,v 1.3 2003/08/03 22:25:30 kojm Exp $ |
|
84 |
+dnl @version: $Id: aclocal.m4,v 1.4 2003/08/06 03:05:50 kojm Exp $ |
|
85 | 85 |
dnl @author Guido Draheim <guidod@gmx.de> STATUS: used often |
86 | 86 |
|
87 | 87 |
AC_DEFUN([AC_CREATE_TARGET_H], |
... | ... |
@@ -4041,7 +4041,7 @@ dnl AC_COMPILE_CHECK_SIZEOF(ptrdiff_t, $headers) |
4041 | 4041 |
dnl AC_COMPILE_CHECK_SIZEOF(off_t, $headers) |
4042 | 4042 |
dnl |
4043 | 4043 |
dnl @author Kaveh Ghazi <ghazi@caip.rutgers.edu> |
4044 |
-dnl @version $Id: aclocal.m4,v 1.3 2003/08/03 22:25:30 kojm Exp $ |
|
4044 |
+dnl @version $Id: aclocal.m4,v 1.4 2003/08/06 03:05:50 kojm Exp $ |
|
4045 | 4045 |
dnl |
4046 | 4046 |
AC_DEFUN([AC_COMPILE_CHECK_SIZEOF], |
4047 | 4047 |
[changequote(<<, >>)dnl |
... | ... |
@@ -62,9 +62,11 @@ struct cfgstruct *parsecfg(const char *cfgfile) |
62 | 62 |
{"FollowDirectorySymlinks", OPT_NOARG}, |
63 | 63 |
{"FollowFileSymlinks", OPT_NOARG}, |
64 | 64 |
{"Foreground", OPT_NOARG}, |
65 |
+ {"Debug", OPT_NOARG}, |
|
65 | 66 |
{"User", OPT_STR}, |
66 | 67 |
{"AllowSupplementaryGroups", OPT_NOARG}, |
67 | 68 |
{"SelfCheck", OPT_NUM}, |
69 |
+ {"VirusEvent", OPT_FULLSTR}, |
|
68 | 70 |
{"ClamukoScanOnLine", OPT_NOARG}, |
69 | 71 |
{"ClamukoScanOnOpen", OPT_NOARG}, |
70 | 72 |
{"ClamukoScanOnClose", OPT_NOARG}, |
... | ... |
@@ -112,6 +114,18 @@ struct cfgstruct *parsecfg(const char *cfgfile) |
112 | 112 |
} |
113 | 113 |
copt = regcfg(copt, name, arg, 0); |
114 | 114 |
break; |
115 |
+ case OPT_FULLSTR: |
|
116 |
+ if(!arg) { |
|
117 |
+ fprintf(stderr, "ERROR: Parse error at line %d: Option %s requires string as argument.\n", line, name); |
|
118 |
+ return NULL; |
|
119 |
+ } |
|
120 |
+ // FIXME: this one is an ugly hack of the above |
|
121 |
+ // case |
|
122 |
+ free(arg); |
|
123 |
+ arg = strstr(buff, " "); |
|
124 |
+ arg = strdup(++arg); |
|
125 |
+ copt = regcfg(copt, name, arg, 0); |
|
126 |
+ break; |
|
115 | 127 |
case OPT_NUM: |
116 | 128 |
if(!isnumb(arg)) { |
117 | 129 |
fprintf(stderr, "ERROR: Parse error at line %d: Option %s requires numerical argument.\n", line, name); |
... | ... |
@@ -29,6 +29,7 @@ |
29 | 29 |
#define OPT_COMPSIZE 3 /* convert kilobytes (k) and megabytes (m) to bytes */ |
30 | 30 |
#define OPT_NOARG 4 /* no argument */ |
31 | 31 |
#define OPT_OPTARG 5 /* argument is optional, it's registered as string */ |
32 |
+#define OPT_FULLSTR 6 /* string argument, but get a full line */ |
|
32 | 33 |
|
33 | 34 |
struct cfgoption { |
34 | 35 |
const char *name; |
... | ... |
@@ -90,6 +90,9 @@ void clamd(struct optstruct *opt) |
90 | 90 |
else |
91 | 91 |
logsize = CL_DEFAULT_LOGSIZE; |
92 | 92 |
|
93 |
+ if(cfgopt(copt, "Debug")) /* enable debug messages in libclamav */ |
|
94 |
+ cl_debug(); |
|
95 |
+ |
|
93 | 96 |
if(cfgopt(copt, "LogVerbose")) |
94 | 97 |
logverbose = 1; |
95 | 98 |
else |
... | ... |
@@ -191,6 +194,7 @@ void clamd(struct optstruct *opt) |
191 | 191 |
if(!cfgopt(copt, "Foreground")) |
192 | 192 |
daemonize(); |
193 | 193 |
|
194 |
+ |
|
194 | 195 |
if(tcpsock) |
195 | 196 |
ret = tcpserver(opt, copt, root); |
196 | 197 |
else |
... | ... |
@@ -243,3 +243,45 @@ int rndnum(unsigned int max) |
243 | 243 |
return generated % max; |
244 | 244 |
} |
245 | 245 |
#endif |
246 |
+ |
|
247 |
+void virusaction(const char *filename, const char *virname, const struct cfgstruct *copt) |
|
248 |
+{ |
|
249 |
+ char *buffer, *pt, *cmd; |
|
250 |
+ struct cfgstruct *cpt; |
|
251 |
+ |
|
252 |
+ |
|
253 |
+ logg("InVirusAction\n", cmd); |
|
254 |
+ if(!(cpt = cfgopt(copt, "VirusEvent"))) |
|
255 |
+ return; |
|
256 |
+ |
|
257 |
+ cmd = strdup(cpt->strarg); |
|
258 |
+ logg("COMMAND: %s\n", cmd); |
|
259 |
+ |
|
260 |
+ buffer = (char *) cli_malloc(strlen(cmd) + strlen(filename) + strlen(virname) + 10, sizeof(char)); |
|
261 |
+ |
|
262 |
+ if((pt = strstr(cmd, "%f"))) { |
|
263 |
+ *pt = 0; pt += 2; |
|
264 |
+ strcpy(buffer, cmd); |
|
265 |
+ strcat(buffer, filename); |
|
266 |
+ strcat(buffer, pt); |
|
267 |
+ free(cmd); |
|
268 |
+ cmd = strdup(buffer); |
|
269 |
+ } |
|
270 |
+ |
|
271 |
+ if((pt = strstr(cmd, "%v"))) { |
|
272 |
+ *pt = 0; pt += 2; |
|
273 |
+ strcpy(buffer, cmd); |
|
274 |
+ strcat(buffer, virname); |
|
275 |
+ strcat(buffer, pt); |
|
276 |
+ free(cmd); |
|
277 |
+ cmd = strdup(buffer); |
|
278 |
+ } |
|
279 |
+ |
|
280 |
+ free(buffer); |
|
281 |
+ |
|
282 |
+ logg("Executing: %s\n", cmd); |
|
283 |
+ /* WARNING: this is uninterruptable ! */ |
|
284 |
+ system(cmd); |
|
285 |
+ |
|
286 |
+ free(cmd); |
|
287 |
+} |
... | ... |
@@ -20,6 +20,7 @@ |
20 | 20 |
#define __OTHERS_H |
21 | 21 |
|
22 | 22 |
#include <stdlib.h> |
23 |
+#include "cfgfile.h" |
|
23 | 24 |
|
24 | 25 |
int mdprintf(int desc, const char *str, ...); |
25 | 26 |
int isnumb(const char *str); |
... | ... |
@@ -37,4 +38,6 @@ int rndnum(unsigned int max); |
37 | 37 |
short use_syslog; |
38 | 38 |
#endif |
39 | 39 |
|
40 |
+void virusaction(const char *filename, const char *virname, const struct cfgstruct *copt); |
|
41 |
+ |
|
40 | 42 |
#endif |
... | ... |
@@ -91,6 +91,7 @@ int dirscan(const char *dirname, char **virname, unsigned long int *scanned, con |
91 | 91 |
if(cl_scanfile(fname, virname, scanned, root, limits, options) == CL_VIRUS) { |
92 | 92 |
mdprintf(odesc, "%s: %s FOUND\n", fname, *virname); |
93 | 93 |
logg("%s: %s FOUND\n", fname, *virname); |
94 |
+ virusaction(fname, *virname, copt); |
|
94 | 95 |
if(!contscan) { |
95 | 96 |
closedir(dd); |
96 | 97 |
free(fname); |
... | ... |
@@ -148,6 +149,7 @@ int scan(const char *filename, unsigned long int *scanned, const struct cl_node |
148 | 148 |
if(ret == CL_VIRUS) { |
149 | 149 |
mdprintf(odesc, "%s: %s FOUND\n", filename, virname); |
150 | 150 |
logg("%s: %s FOUND\n", filename, virname); |
151 |
+ virusaction(filename, virname, copt); |
|
151 | 152 |
} else if(ret != CL_CLEAN) { |
152 | 153 |
mdprintf(odesc, "%s: %s ERROR\n", filename, cl_perror(ret)); |
153 | 154 |
logg("%s: %s ERROR\n", filename, cl_perror(ret)); |
... | ... |
@@ -262,6 +264,7 @@ int scanstream(int odesc, unsigned long int *scanned, const struct cl_node *root |
262 | 262 |
if(ret == CL_VIRUS) { |
263 | 263 |
mdprintf(odesc, "stream: %s FOUND\n", virname); |
264 | 264 |
logg("stream: %s FOUND\n", virname); |
265 |
+ virusaction("InputStream", virname, copt); |
|
265 | 266 |
} else if(ret != CL_CLEAN) { |
266 | 267 |
mdprintf(odesc, "stream: %s ERROR\n", cl_perror(ret)); |
267 | 268 |
logg("stream: %s ERROR\n", cl_perror(ret)); |
... | ... |
@@ -17,7 +17,7 @@ Size in bytes. You can use a 'M' or 'm' modifiers for megabytes and a 'K' or 'k' |
17 | 17 |
.TP |
18 | 18 |
\fBNUMBER\fR |
19 | 19 |
Unsigned integer. |
20 |
-.SH "OPTIONS" |
|
20 |
+.SH "DIRECTIVES" |
|
21 | 21 |
.LP |
22 | 22 |
When some option is not used (hashed or doesn't exist in the configuration file), clamd takes a default action. |
23 | 23 |
.TP |
... | ... |
@@ -104,6 +104,13 @@ Do internal checks every NUMBER seconds. In some cases it's able to fix a proble |
104 | 104 |
.br |
105 | 105 |
Default: 3600 |
106 | 106 |
.TP |
107 |
+\fBVirusEvent COMMAND\fR |
|
108 |
+Execute COMMAND when virus is found. In the command string %v and %f will be replaced by the virus name and the infected file name respectively. |
|
109 |
+\fBSECURITY WARNING: Make sure the virus event command cannot be exploited, eg. by using some special file name when %f is used. Always use a full path to the command. Never delete/move files with this directive ! |
|
110 |
+\fR |
|
111 |
+.br |
|
112 |
+Default: disabled. |
|
113 |
+.TP |
|
107 | 114 |
\fBUser STRING\fR |
108 | 115 |
When started by root, drop priviledges to a specified user. |
109 | 116 |
.br |
... | ... |
@@ -91,6 +91,15 @@ MaxDirectoryRecursion 15 |
91 | 91 |
# By default clamd checks itself every 3600 seconds (1 hour). |
92 | 92 |
#SelfCheck 600 |
93 | 93 |
|
94 |
+# Execute a command when virus is found. In the command string %v and %f will |
|
95 |
+# be replaced by the virus name and the infected file name respectively. |
|
96 |
+# |
|
97 |
+# SECURITY WARNING: Make sure the virus event command cannot be exploited, |
|
98 |
+# eg. by using some special file name when %f is used. |
|
99 |
+# Always use a full path to the command. |
|
100 |
+# Never delete/move files with this directive ! |
|
101 |
+#VirusEvent /usr/local/bin/send_sms 123456789 "VIRUS ALERT: %f: %v" |
|
102 |
+ |
|
94 | 103 |
# Run as selected user (clamd must be started by root). |
95 | 104 |
# By default it doesn't drop privileges. |
96 | 105 |
#User clamav |
... | ... |
@@ -102,6 +111,9 @@ MaxDirectoryRecursion 15 |
102 | 102 |
# Don't fork into background. Useful in debugging. |
103 | 103 |
#Foreground |
104 | 104 |
|
105 |
+# Enable debug messages in libclamav. |
|
106 |
+#Debug |
|
107 |
+ |
|
105 | 108 |
## |
106 | 109 |
## Mail support |
107 | 110 |
## |
... | ... |
@@ -62,9 +62,11 @@ struct cfgstruct *parsecfg(const char *cfgfile) |
62 | 62 |
{"FollowDirectorySymlinks", OPT_NOARG}, |
63 | 63 |
{"FollowFileSymlinks", OPT_NOARG}, |
64 | 64 |
{"Foreground", OPT_NOARG}, |
65 |
+ {"Debug", OPT_NOARG}, |
|
65 | 66 |
{"User", OPT_STR}, |
66 | 67 |
{"AllowSupplementaryGroups", OPT_NOARG}, |
67 | 68 |
{"SelfCheck", OPT_NUM}, |
69 |
+ {"VirusEvent", OPT_FULLSTR}, |
|
68 | 70 |
{"ClamukoScanOnLine", OPT_NOARG}, |
69 | 71 |
{"ClamukoScanOnOpen", OPT_NOARG}, |
70 | 72 |
{"ClamukoScanOnClose", OPT_NOARG}, |
... | ... |
@@ -112,6 +114,18 @@ struct cfgstruct *parsecfg(const char *cfgfile) |
112 | 112 |
} |
113 | 113 |
copt = regcfg(copt, name, arg, 0); |
114 | 114 |
break; |
115 |
+ case OPT_FULLSTR: |
|
116 |
+ if(!arg) { |
|
117 |
+ fprintf(stderr, "ERROR: Parse error at line %d: Option %s requires string as argument.\n", line, name); |
|
118 |
+ return NULL; |
|
119 |
+ } |
|
120 |
+ // FIXME: this one is an ugly hack of the above |
|
121 |
+ // case |
|
122 |
+ free(arg); |
|
123 |
+ arg = strstr(buff, " "); |
|
124 |
+ arg = strdup(++arg); |
|
125 |
+ copt = regcfg(copt, name, arg, 0); |
|
126 |
+ break; |
|
115 | 127 |
case OPT_NUM: |
116 | 128 |
if(!isnumb(arg)) { |
117 | 129 |
fprintf(stderr, "ERROR: Parse error at line %d: Option %s requires numerical argument.\n", line, name); |
... | ... |
@@ -2,7 +2,7 @@ |
2 | 2 |
* Author: |
3 | 3 |
* Guido Draheim <guidod@gmx.de> |
4 | 4 |
* |
5 |
- * Copyright (c) 2001,2002,2003 Guido Draheim |
|
5 |
+ * Copyright (c) 2001 Guido Draheim |
|
6 | 6 |
* All rights reserved, |
7 | 7 |
* use under the restrictions of the |
8 | 8 |
* Lesser GNU General Public License |
... | ... |
@@ -53,34 +53,15 @@ |
53 | 53 |
#define _zzip_inline inline |
54 | 54 |
#endif |
55 | 55 |
#endif |
56 |
-#ifndef _zzip_size_t |
|
57 |
-#ifdef ZZIP_size_t |
|
58 |
-#define _zzip_size_t ZZIP_size_t |
|
59 |
-#else |
|
60 |
-#define _zzip_size_t size_t |
|
61 |
-#endif |
|
62 |
-#endif |
|
63 |
-#ifndef _zzip_ssize_t |
|
64 |
-#ifdef ZZIP_ssize_t |
|
65 |
-#define _zzip_ssize_t ZZIP_ssize_t |
|
66 |
-#else |
|
67 |
-#define _zzip_ssize_t ssize_t |
|
68 |
-#endif |
|
69 |
-#endif |
|
70 | 56 |
|
71 | 57 |
/* whether this library shall use a 64bit off_t largefile variant in 64on32: */ |
72 | 58 |
/* (some exported names must be renamed to avoid bad calls after linking) */ |
73 |
-#if defined ZZIP_LARGEFILE_SENSITIVE |
|
74 |
-# if _FILE_OFFSET_BITS+0 == 64 |
|
75 |
-# define ZZIP_LARGEFILE_RENAME |
|
76 |
-# elif defined _LARGE_FILES /* used on older AIX to get at 64bit off_t */ |
|
77 |
-# define ZZIP_LARGEFILE_RENAME |
|
78 |
-# elif defined _ZZIP_LARGEFILE /* or simply use this one for zzip64 runs */ |
|
79 |
-# define ZZIP_LARGEFILE_RENAME |
|
80 |
-# endif |
|
59 |
+#if defined ZZIP_LARGEFILE_SENSITIVE && _FILE_OFFSET_BITS+0 == 64 |
|
60 |
+#define ZZIP_LARGEFILE_RENAME |
|
61 |
+#elif defined _LARGE_FILES /* on AIX */ |
|
62 |
+#define ZZIP_LARGEFILE_RENAME |
|
81 | 63 |
#endif |
82 |
- |
|
83 |
-/* if the environment did not setup these for 64bit off_t largefile... */ |
|
64 |
+/* if some were forgotten but required to have 64bit off_t largefile.. */ |
|
84 | 65 |
#ifdef ZZIP_LARGEFILE_RENAME |
85 | 66 |
# ifndef _FILE_OFFSET_BITS |
86 | 67 |
# ifdef ZZIP__FILE_OFFSET_BITS /* == 64 */ |
... | ... |
@@ -89,12 +70,7 @@ |
89 | 89 |
# endif |
90 | 90 |
# ifndef _LARGE_FILES |
91 | 91 |
# ifdef ZZIP__LARGE_FILES /* == 1 */ |
92 |
-# define _LARGE_FILES ZZIP__LARGE_FILES |
|
93 |
-# endif |
|
94 |
-# endif |
|
95 |
-# ifndef _LARGEFILE_SOURCE |
|
96 |
-# ifdef ZZIP__LARGEFILE_SOURCE /* == 1 */ |
|
97 |
-# define _LARGEFILE_SOURCE ZZIP__LARGEFILE_SOURCE |
|
92 |
+# define _LARGE_FILES 1 |
|
98 | 93 |
# endif |
99 | 94 |
# endif |
100 | 95 |
#endif |
... | ... |
@@ -165,11 +141,6 @@ |
165 | 165 |
#define __attribute__(X) |
166 | 166 |
#endif |
167 | 167 |
|
168 |
-#if defined ZZIP_EXPORTS || defined ZZIPLIB_EXPORTS |
|
169 |
-# undef ZZIP_DLL |
|
170 |
-#define ZZIP_DLL 1 |
|
171 |
-#endif |
|
172 |
- |
|
173 | 168 |
/* based on zconf.h : */ |
174 | 169 |
/* compile with -DZZIP_DLL for Windows DLL support */ |
175 | 170 |
#if defined ZZIP_DLL |
... | ... |
@@ -1,3 +1,4 @@ |
1 |
+#define USE_DIRENT 0 |
|
1 | 2 |
/* |
2 | 3 |
* Author: |
3 | 4 |
* Guido Draheim <guidod@gmx.de> |
... | ... |
@@ -38,8 +39,6 @@ |
38 | 38 |
# endif |
39 | 39 |
#endif |
40 | 40 |
|
41 |
-#define USE_DIRENT 0 |
|
42 |
- |
|
43 | 41 |
/** |
44 | 42 |
* This function is the equivalent of a => rewinddir(2) for a realdir or |
45 | 43 |
* the zipfile in place of a directory. The ZZIP_DIR handle returned from |
... | ... |
@@ -88,14 +88,17 @@ zzip_file_saveoffset(ZZIP_FILE * fp) |
88 | 88 |
return 0; |
89 | 89 |
} |
90 | 90 |
|
91 |
-# ifndef ZZIP_CHECK_BACKSLASH_DIRSEPARATOR /* NOTE: also default */ |
|
92 |
-# define ZZIP_CHECK_BACKSLASH_DIRSEPARATOR 0 /* to "NO" on win32 ! */ |
|
91 |
+ |
|
92 |
+ |
|
93 |
+# ifndef ZZIP_CHECK_BACKSLASH_DIRSEPARATOR |
|
94 |
+# define ZZIP_CHECK_BACKSLASH_DIRSEPARATOR 0 |
|
93 | 95 |
# endif |
94 | 96 |
|
95 | 97 |
# if !defined strcasecmp && !defined ZZIP_HAVE_STRCASECMP |
96 | 98 |
# define ZZIP_CHECK_BACKSLASH_DIRSEPARATOR 1 |
97 | 99 |
# endif |
98 | 100 |
|
101 |
+ |
|
99 | 102 |
#if ! ZZIP_CHECK_BACKSLASH_DIRSEPARATOR+0 |
100 | 103 |
#define dirsep_strrchr(N,C) strrchr(N,C) |
101 | 104 |
#define dirsep_casecmp strcasecmp |
... | ... |
@@ -219,11 +222,11 @@ zzip_file_open(ZZIP_DIR * dir, zzip_char_t* name, int o_mode) |
219 | 219 |
|
220 | 220 |
{ /* skip local header - should test tons of other info, |
221 | 221 |
* but trust that those are correct */ |
222 |
- zzip_ssize_t dataoff; |
|
222 |
+ int dataoff; |
|
223 | 223 |
struct zzip_file_header * p = (void*) fp->buf32k; |
224 | 224 |
|
225 | 225 |
dataoff = dir->io->read(dir->fd, (void*)p, sizeof(*p)); |
226 |
- if (dataoff < (zzip_ssize_t)sizeof(*p)) |
|
226 |
+ if (dataoff < (int) sizeof(*p)) |
|
227 | 227 |
{ err = ZZIP_DIR_READ; goto error; } |
228 | 228 |
if (! ZZIP_FILE_HEADER_CHECKMAGIC(p)) /* PK\3\4 */ |
229 | 229 |
{ err = ZZIP_CORRUPTED; goto error; } |
... | ... |
@@ -320,12 +323,12 @@ zzip_close(ZZIP_FILE* fp) |
320 | 320 |
* required just that but the latest zlib would work just fine with |
321 | 321 |
* a smaller buffer. |
322 | 322 |
*/ |
323 |
-zzip_ssize_t |
|
324 |
-zzip_file_read(ZZIP_FILE * fp, char * buf, zzip_size_t len) |
|
323 |
+int |
|
324 |
+zzip_file_read(ZZIP_FILE * fp, char * buf, int len) |
|
325 | 325 |
{ |
326 | 326 |
ZZIP_DIR * dir; |
327 |
- zzip_size_t l; |
|
328 |
- zzip_ssize_t rv; |
|
327 |
+ int l; |
|
328 |
+ int rv; |
|
329 | 329 |
|
330 | 330 |
if (! fp || ! fp->dir) return 0; |
331 | 331 |
|
... | ... |
@@ -355,15 +358,14 @@ zzip_file_read(ZZIP_FILE * fp, char * buf, zzip_size_t len) |
355 | 355 |
|
356 | 356 |
do { |
357 | 357 |
int err; |
358 |
- zzip_size_t startlen; |
|
358 |
+ int startlen; |
|
359 | 359 |
|
360 | 360 |
if (fp->crestlen > 0 && fp->d_stream.avail_in == 0) |
361 | 361 |
{ |
362 |
- zzip_size_t cl = ( fp->crestlen < ZZIP_32K ? |
|
363 |
- fp->crestlen : ZZIP_32K ); |
|
364 |
- /* zzip_size_t cl = fp->crestlen > 128 ? 128 : fp->crestlen; */ |
|
362 |
+ int cl = fp->crestlen > ZZIP_32K ? ZZIP_32K : fp->crestlen; |
|
363 |
+ /* int cl = fp->crestlen > 128? 128: fp->crestlen; */ |
|
365 | 364 |
|
366 |
- zzip_ssize_t i = fp->io->read(dir->fd, fp->buf32k, cl); |
|
365 |
+ int i = fp->io->read(dir->fd, fp->buf32k, cl); |
|
367 | 366 |
if (i <= 0) |
368 | 367 |
{ |
369 | 368 |
dir->errcode = ZZIP_DIR_READ; /* or ZZIP_DIR_READ_EOF ? */ |
... | ... |
@@ -410,14 +412,14 @@ zzip_file_read(ZZIP_FILE * fp, char * buf, zzip_size_t len) |
410 | 410 |
* perform a normal => read(2)-call, otherwise => zzip_file_read is called |
411 | 411 |
* to decompress the data stream and any error is mapped to => errno(3). |
412 | 412 |
*/ |
413 |
-zzip_ssize_t |
|
414 |
-zzip_read(ZZIP_FILE * fp, char * buf, zzip_size_t len) |
|
413 |
+int |
|
414 |
+zzip_read(ZZIP_FILE * fp, char * buf, int len) |
|
415 | 415 |
{ |
416 | 416 |
if (! fp) return 0; |
417 | 417 |
if (! fp->dir) |
418 | 418 |
{ return fp->io->read(fp->fd, buf, len); } /* stat fd */ |
419 | 419 |
else |
420 |
- { register zzip_ssize_t v; |
|
420 |
+ { register int v; |
|
421 | 421 |
v = zzip_file_read(fp, buf, len); |
422 | 422 |
if (v == -1) { errno = zzip_errno(fp->dir->errcode); } |
423 | 423 |
return v; |
... | ... |
@@ -426,8 +428,8 @@ zzip_read(ZZIP_FILE * fp, char * buf, zzip_size_t len) |
426 | 426 |
|
427 | 427 |
/** => zzip_read |
428 | 428 |
*/ |
429 |
-zzip_size_t |
|
430 |
-zzip_fread(void *ptr, zzip_size_t size, zzip_size_t nmemb, ZZIP_FILE *file) |
|
429 |
+int |
|
430 |
+zzip_fread(void *ptr, int size, int nmemb, ZZIP_FILE *file) |
|
431 | 431 |
{ |
432 | 432 |
if (! size) size=1; |
433 | 433 |
return zzip_read (file, ptr, size*nmemb)/size; |
... | ... |
@@ -712,7 +714,7 @@ zzip_open_shared_io (ZZIP_FILE* stream, |
712 | 712 |
/* see if we can share the same zip directory */ |
713 | 713 |
if (stream && stream->dir && stream->dir->realname) |
714 | 714 |
{ |
715 |
- zzip_size_t len = strlen (stream->dir->realname); |
|
715 |
+ int len = strlen (stream->dir->realname); |
|
716 | 716 |
if (! memcmp (filename, stream->dir->realname, len) && |
717 | 717 |
filename[len] == '/' && filename[len+1]) |
718 | 718 |
{ |
... | ... |
@@ -862,10 +864,10 @@ zzip_rewind(ZZIP_FILE *fp) |
862 | 862 |
* how gzio implements it, so I'm not sure there is a better way |
863 | 863 |
* without using the internals of the algorithm. |
864 | 864 |
*/ |
865 |
-zzip_off_t |
|
866 |
-zzip_seek(ZZIP_FILE * fp, zzip_off_t offset, int whence) |
|
865 |
+int |
|
866 |
+zzip_seek(ZZIP_FILE * fp, int offset, int whence) |
|
867 | 867 |
{ |
868 |
- zzip_off_t cur_pos, rel_ofs, read_size, ofs; |
|
868 |
+ int cur_pos, rel_ofs, read_size, ofs; |
|
869 | 869 |
ZZIP_DIR *dir; |
870 | 870 |
|
871 | 871 |
if (! fp) |
... | ... |
@@ -873,7 +875,7 @@ zzip_seek(ZZIP_FILE * fp, zzip_off_t offset, int whence) |
873 | 873 |
|
874 | 874 |
if (! fp->dir) |
875 | 875 |
{ /* stat fd */ |
876 |
- return fp->io->seeks(fp->fd, offset, whence); |
|
876 |
+ return fp->io->seeks(fp->fd,offset,whence); |
|
877 | 877 |
} |
878 | 878 |
|
879 | 879 |
cur_pos = zzip_tell(fp); |
... | ... |
@@ -912,7 +914,7 @@ zzip_seek(ZZIP_FILE * fp, zzip_off_t offset, int whence) |
912 | 912 |
if (read_size < 0) /* bad offset, before beginning of file */ |
913 | 913 |
return -1; |
914 | 914 |
|
915 |
- if (read_size + cur_pos > (zzip_off_t)fp->usize) /* bad offset, past EOF */ |
|
915 |
+ if (read_size + cur_pos > fp->usize) /* bad offset, past EOF */ |
|
916 | 916 |
return -1; |
917 | 917 |
|
918 | 918 |
if (read_size == 0) /* nothing to read */ |
... | ... |
@@ -951,10 +953,10 @@ zzip_seek(ZZIP_FILE * fp, zzip_off_t offset, int whence) |
951 | 951 |
|
952 | 952 |
while (read_size > 0) |
953 | 953 |
{ |
954 |
- zzip_off_t size = ZZIP_32K; |
|
955 |
- if (read_size < size/*32K*/) size = read_size; |
|
954 |
+ int size = ZZIP_32K; |
|
955 |
+ if (read_size < ZZIP_32K) size = (int)read_size; |
|
956 | 956 |
|
957 |
- size = zzip_file_read(fp, buf, (zzip_size_t)size); |
|
957 |
+ size = zzip_file_read(fp, buf, size); |
|
958 | 958 |
if (size <= 0) { free(buf); return -1; } |
959 | 959 |
|
960 | 960 |
read_size -= size; |
... | ... |
@@ -977,7 +979,7 @@ zzip_seek(ZZIP_FILE * fp, zzip_off_t offset, int whence) |
977 | 977 |
* calculated from the amount of data left and the total uncompressed |
978 | 978 |
* size; |
979 | 979 |
*/ |
980 |
-zzip_off_t |
|
980 |
+int |
|
981 | 981 |
zzip_tell(ZZIP_FILE * fp) |
982 | 982 |
{ |
983 | 983 |
if (! fp) |
... | ... |
@@ -65,10 +65,10 @@ struct zzip_file |
65 | 65 |
struct zzip_dir* dir; |
66 | 66 |
int fd; |
67 | 67 |
int method; |
68 |
- zzip_size_t restlen; |
|
69 |
- zzip_size_t crestlen; |
|
70 |
- zzip_size_t usize; |
|
71 |
- zzip_size_t csize; |
|
68 |
+ int restlen; |
|
69 |
+ int crestlen; |
|
70 |
+ int usize; |
|
71 |
+ int csize; |
|
72 | 72 |
/* added dataoffset member - data offset from start of zipfile*/ |
73 | 73 |
zzip_off_t dataoffset; |
74 | 74 |
char* buf32k; |
... | ... |
@@ -24,11 +24,8 @@ |
24 | 24 |
#include <sys/stat.h> |
25 | 25 |
#endif |
26 | 26 |
|
27 |
- |
|
28 |
-#define __sizeof(X) ((zzip_ssize_t)(sizeof(X))) |
|
29 |
- |
|
30 |
-/* per default, we use a little hack to correct bad z_rootseek parts */ |
|
31 |
-#define ZZIP_CORRECT_ROOTSEEK 1 |
|
27 |
+//#include "__mmap.h" |
|
28 |
+//#include "__debug.h" |
|
32 | 29 |
|
33 | 30 |
/* ------------------------- fetch helpers --------------------------------- */ |
34 | 31 |
|
... | ... |
@@ -50,86 +47,6 @@ uint16_t __zzip_get16(unsigned char * s) |
50 | 50 |
return ((uint16_t)s[1] << 8) | (uint16_t)s[0]; |
51 | 51 |
} |
52 | 52 |
|
53 |
-/* --------------------------- internals -------------------------------- */ |
|
54 |
-/* internal functions of zziplib, avoid at all cost, changes w/o warning. |
|
55 |
- * we do export them for debugging purpose and special external tools |
|
56 |
- * which know what they do and which can adapt from version to version |
|
57 |
- */ |
|
58 |
- |
|
59 |
-int __zzip_find_disk_trailer( int fd, zzip_off_t filesize, |
|
60 |
- struct zzip_disk_trailer * trailer, |
|
61 |
- zzip_plugin_io_t io); |
|
62 |
-int __zzip_parse_root_directory( int fd, |
|
63 |
- struct zzip_disk_trailer * trailer, |
|
64 |
- struct zzip_dir_hdr ** hdr_return, |
|
65 |
- zzip_plugin_io_t io); |
|
66 |
- |
|
67 |
-_zzip_inline char* __zzip_aligned4(char* p); |
|
68 |
- |
|
69 |
-/* ------------------------ harden routines ------------------------------ */ |
|
70 |
- |
|
71 |
-#ifdef ZZIP_HARDEN |
|
72 |
-/* |
|
73 |
- * check for inconsistent values in trailer and prefer lower seek value |
|
74 |
- * - we fix values assuming the root directory was written at the end |
|
75 |
- * and it is just before the zip trailer. Therefore, ... |
|
76 |
- */ |
|
77 |
-_zzip_inline static void __fixup_rootseek( |
|
78 |
- zzip_off_t offset_of_trailer, |
|
79 |
- struct zzip_disk_trailer* trailer) |
|
80 |
-{ |
|
81 |
- if ( (zzip_off_t) ZZIP_GET32(trailer->z_rootseek) > |
|
82 |
- offset_of_trailer - (zzip_off_t) ZZIP_GET32(trailer->z_rootsize) && |
|
83 |
- offset_of_trailer > (zzip_off_t) ZZIP_GET32(trailer->z_rootsize)) |
|
84 |
- { |
|
85 |
- register zzip_off_t offset; |
|
86 |
- offset = offset_of_trailer - ZZIP_GET32(trailer->z_rootsize); |
|
87 |
- trailer->z_rootseek[0] = offset & 0xff; |
|
88 |
- trailer->z_rootseek[1] = offset >> 8 & 0xff; |
|
89 |
- trailer->z_rootseek[2] = offset >> 16 & 0xff; |
|
90 |
- trailer->z_rootseek[3] = offset >> 24 & 0xff; |
|
91 |
- } |
|
92 |
-} |
|
93 |
-#define __correct_rootseek(A,B,C) |
|
94 |
- |
|
95 |
-#elif defined ZZIP_CORRECT_ROOTSEEK |
|
96 |
-/* store the seekvalue of the trailer into the "z_magic" field and with |
|
97 |
- * a 64bit off_t we overwrite z_disk/z_finaldisk as well. If you change |
|
98 |
- * anything in zziplib or dump the trailer structure then watch out that |
|
99 |
- * these are still unused, so that this code may still (ab)use those. */ |
|
100 |
-#define __fixup_rootseek(_offset_of_trailer, _trailer) \ |
|
101 |
- *(zzip_off_t*)_trailer = _offset_of_trailer; |
|
102 |
-#define __correct_rootseek( _u_rootseek, _u_rootsize, _trailer) \ |
|
103 |
- if (_u_rootseek > *(zzip_off_t*)_trailer - _u_rootsize) \ |
|
104 |
- _u_rootseek = *(zzip_off_t*)_trailer - _u_rootsize; |
|
105 |
-#else |
|
106 |
-#define __fixup_rootseek(A,B) |
|
107 |
-#define __correct_rootseek(A,B,C) |
|
108 |
-#endif |
|
109 |
- |
|
110 |
- |
|
111 |
-#ifdef DEBUG |
|
112 |
-_zzip_inline static void __debug_dir_hdr (struct zzip_dir_hdr* hdr) |
|
113 |
-{ |
|
114 |
- if (sizeof(struct zzip_dir_hdr) > sizeof(struct zzip_root_dirent)) |
|
115 |
- { WARN1("internal sizeof-mismatch may break wreakage"); } |
|
116 |
- /* the internal directory structure is never bigger than the |
|
117 |
- * external zip central directory space had been beforehand |
|
118 |
- * (as long as the following assertion holds...) |
|
119 |
- */ |
|
120 |
- |
|
121 |
- if (((unsigned)hdr)&3) |
|
122 |
- { NOTE1("this machine's malloc(3) returns sth. not u32-aligned"); } |
|
123 |
- /* we assume that if this machine's malloc has returned a non-aligned |
|
124 |
- * memory block, then it is actually safe to access misaligned data, and |
|
125 |
- * since it does only affect the first hdr it should not even bring about |
|
126 |
- * too much of that cpu's speed penalty |
|
127 |
- */ |
|
128 |
-} |
|
129 |
-#else |
|
130 |
-#define __debug_dir_hdr(X) |
|
131 |
-#endif |
|
132 |
- |
|
133 | 53 |
/* -------------------------- low-level interface -------------------------- */ |
134 | 54 |
|
135 | 55 |
#if defined BUFSIZ |
... | ... |
@@ -153,7 +70,11 @@ __zzip_find_disk_trailer(int fd, zzip_off_t filesize, |
153 | 153 |
struct zzip_disk_trailer * trailer, |
154 | 154 |
zzip_plugin_io_t io) |
155 | 155 |
{ |
156 |
+#ifdef DEBUG |
|
157 |
+#define return(val) { e=val; goto cleanup; } |
|
158 |
+#else |
|
156 | 159 |
#define return(val) { e=val; goto cleanup; } |
160 |
+#endif |
|
157 | 161 |
register int e; |
158 | 162 |
|
159 | 163 |
#ifndef _LOWSTK |
... | ... |
@@ -163,13 +84,13 @@ __zzip_find_disk_trailer(int fd, zzip_off_t filesize, |
163 | 163 |
char* buf = malloc(2*ZZIP_BUFSIZ); |
164 | 164 |
#endif |
165 | 165 |
zzip_off_t offset = 0; |
166 |
- zzip_off_t maplen = 0; /* mmap(),read(),getpagesize() use size_t !! */ |
|
166 |
+ size_t maplen = 0; |
|
167 | 167 |
char* fd_map = 0; |
168 | 168 |
|
169 | 169 |
if (!trailer) |
170 | 170 |
{ return(EINVAL); } |
171 | 171 |
|
172 |
- if (filesize < __sizeof(struct zzip_disk_trailer)) |
|
172 |
+ if (filesize < sizeof(struct zzip_disk_trailer)) |
|
173 | 173 |
{ return(ZZIP_DIR_TOO_SHORT); } |
174 | 174 |
|
175 | 175 |
if (!buf) |
... | ... |
@@ -178,7 +99,8 @@ __zzip_find_disk_trailer(int fd, zzip_off_t filesize, |
178 | 178 |
offset = filesize; /* a.k.a. old offset */ |
179 | 179 |
while(1) /* outer loop */ |
180 | 180 |
{ |
181 |
- register unsigned char* mapped; |
|
181 |
+ register unsigned char* p; |
|
182 |
+ register unsigned char* s; |
|
182 | 183 |
|
183 | 184 |
if (offset <= 0) { return(ZZIP_DIR_EDH_MISSING); } |
184 | 185 |
|
... | ... |
@@ -206,40 +128,35 @@ __zzip_find_disk_trailer(int fd, zzip_off_t filesize, |
206 | 206 |
|
207 | 207 |
if (io->seeks(fd, offset, SEEK_SET) < 0) |
208 | 208 |
{ return(ZZIP_DIR_SEEK); } |
209 |
- if (io->read(fd, buf, (zzip_size_t)maplen) < (zzip_ssize_t)maplen) |
|
209 |
+ if (io->read(fd, buf, maplen) < (long)maplen) |
|
210 | 210 |
{ return(ZZIP_DIR_READ); } |
211 |
- mapped = buf; /* success */ |
|
211 |
+ p = buf; /* success */ |
|
212 | 212 |
|
213 | 213 |
|
214 |
- {/* now, check for the trailer-magic, hopefully near the end of file */ |
|
215 |
- register unsigned char* end = mapped + maplen; |
|
216 |
- register unsigned char* tail; |
|
217 |
- for (tail = end-1; (tail >= mapped); tail--) |
|
218 |
- { |
|
219 |
- if ((*tail == 'P') && /* quick pre-check for trailer magic */ |
|
220 |
- end-tail >= __sizeof(*trailer)-2 && |
|
221 |
- ZZIP_DISK_TRAILER_CHECKMAGIC(tail)) |
|
222 |
- { |
|
223 |
- /* if the file-comment is not present, it happens |
|
224 |
- that the z_comment field often isn't either */ |
|
225 |
- if (end-tail >= __sizeof(*trailer)) |
|
226 |
- { |
|
227 |
- memcpy (trailer, tail, sizeof(*trailer)); |
|
228 |
- }else{ |
|
229 |
- memcpy (trailer, tail, sizeof(*trailer)-2); |
|
230 |
- trailer->z_comment[0] = 0; |
|
231 |
- trailer->z_comment[1] = 0; |
|
232 |
- } |
|
233 |
- |
|
234 |
- __fixup_rootseek (offset + tail-mapped, trailer); |
|
235 |
- { return(0); } |
|
236 |
- } |
|
237 |
- } |
|
214 |
+ /* now, check for the trailer-magic, hopefully near the end of file */ |
|
215 |
+ for (s = p + maplen-1; (s >= p); s--) |
|
216 |
+ { |
|
217 |
+ if (*s == 'P' |
|
218 |
+ && p+maplen-1-s > sizeof(*trailer)-2 |
|
219 |
+ && ZZIP_DISK_TRAILER_CHECKMAGIC(s)) |
|
220 |
+ { |
|
221 |
+ /* if the file-comment is not present, it happens |
|
222 |
+ that the z_comment field often isn't either */ |
|
223 |
+ if (p+maplen-1-s > sizeof(*trailer)) |
|
224 |
+ { memcpy (trailer, s, sizeof(*trailer)); } |
|
225 |
+ else |
|
226 |
+ { |
|
227 |
+ memcpy (trailer, s, sizeof(*trailer)-2); |
|
228 |
+ trailer->z_comment[0] = 0; trailer->z_comment[1] = 0; |
|
229 |
+ } |
|
230 |
+ |
|
231 |
+ { return(0); } |
|
232 |
+ } |
|
238 | 233 |
} |
239 | 234 |
|
240 | 235 |
} /*outer loop*/ |
241 | 236 |
|
242 |
-cleanup: |
|
237 |
+ cleanup: |
|
243 | 238 |
# ifdef _LOWSTK |
244 | 239 |
free(buf); |
245 | 240 |
# endif |
... | ... |
@@ -257,8 +174,8 @@ cleanup: |
257 | 257 |
_zzip_inline char* __zzip_aligned4(char* p) |
258 | 258 |
{ |
259 | 259 |
#define aligned4 __zzip_aligned4 |
260 |
- p += ((long)p)&1; /* warnings about truncation of a "pointer" */ |
|
261 |
- p += ((long)p)&2; /* to a "long int" may be safely ignored :) */ |
|
260 |
+ p += ((long)p)&1; |
|
261 |
+ p += ((long)p)&2; |
|
262 | 262 |
return p; |
263 | 263 |
} |
264 | 264 |
|
... | ... |
@@ -279,19 +196,34 @@ __zzip_parse_root_directory(int fd, |
279 | 279 |
struct zzip_dir_hdr * hdr0; |
280 | 280 |
uint16_t * p_reclen = 0; |
281 | 281 |
short entries; |
282 |
- long offset; /* offset from start of root directory */ |
|
283 |
- char* fd_map = 0; |
|
282 |
+ long offset; |
|
283 |
+ char* fd_map = 0; |
|
284 | 284 |
int32_t fd_gap = 0; |
285 | 285 |
uint16_t u_entries = ZZIP_GET16(trailer->z_entries); |
286 | 286 |
uint32_t u_rootsize = ZZIP_GET32(trailer->z_rootsize); |
287 | 287 |
uint32_t u_rootseek = ZZIP_GET32(trailer->z_rootseek); |
288 |
- __correct_rootseek (u_rootseek, u_rootsize, trailer); |
|
289 | 288 |
|
290 | 289 |
hdr0 = (struct zzip_dir_hdr*) malloc(u_rootsize); |
291 | 290 |
if (!hdr0) |
292 | 291 |
return ZZIP_DIRSIZE; |
293 |
- hdr = hdr0; __debug_dir_hdr (hdr); |
|
292 |
+ hdr = hdr0; |
|
294 | 293 |
|
294 |
+# ifdef DEBUG |
|
295 |
+ if (sizeof(struct zzip_dir_hdr) > sizeof(struct zzip_root_dirent)) |
|
296 |
+ { WARN1("internal sizeof-mismatch may break wreakage"); } |
|
297 |
+ /* the internal directory structure is never bigger than the |
|
298 |
+ * external zip central directory space had been beforehand |
|
299 |
+ * (as long as the following assertion holds...) |
|
300 |
+ */ |
|
301 |
+ |
|
302 |
+ if (((unsigned)hdr0)&3) |
|
303 |
+ { NOTE1("this machine's malloc(3) returns sth. not u32-aligned"); } |
|
304 |
+ /* we assume that if this machine's malloc has returned a non-aligned |
|
305 |
+ * memory block, then it is actually safe to access misaligned data, and |
|
306 |
+ * since it does only affect the first hdr it should not even bring about |
|
307 |
+ * too much of that cpu's speed penalty |
|
308 |
+ */ |
|
309 |
+# endif |
|
295 | 310 |
|
296 | 311 |
for (entries=u_entries, offset=0; entries > 0; entries--) |
297 | 312 |
{ |
... | ... |
@@ -304,13 +236,11 @@ __zzip_parse_root_directory(int fd, |
304 | 304 |
{ |
305 | 305 |
if (io->seeks(fd, u_rootseek+offset, SEEK_SET) < 0) |
306 | 306 |
return ZZIP_DIR_SEEK; |
307 |
- if (io->read(fd, &dirent, sizeof(dirent)) < __sizeof(dirent)) |
|
307 |
+ if (io->read(fd, &dirent, sizeof(dirent)) < sizeof(dirent)) |
|
308 | 308 |
return ZZIP_DIR_READ; |
309 | 309 |
d = &dirent; |
310 | 310 |
} |
311 | 311 |
|
312 |
- if (offset+sizeof(*d) > u_rootsize) |
|
313 |
- |
|
314 | 312 |
# if 0 && defined DEBUG |
315 | 313 |
zzip_debug_xbuf ((unsigned char*) d, sizeof(*d) + 8); |
316 | 314 |
# endif |
... | ... |
@@ -318,7 +248,8 @@ __zzip_parse_root_directory(int fd, |
318 | 318 |
u_extras = ZZIP_GET16(d->z_extras); |
319 | 319 |
u_comment = ZZIP_GET16(d->z_comment); |
320 | 320 |
u_namlen = ZZIP_GET16(d->z_namlen); |
321 |
- |
|
321 |
+ |
|
322 |
+ |
|
322 | 323 |
/* writes over the read buffer, Since the structure where data is |
323 | 324 |
copied is smaller than the data in buffer this can be done. |
324 | 325 |
It is important that the order of setting the fields is considered |
... | ... |
@@ -333,11 +264,10 @@ __zzip_parse_root_directory(int fd, |
333 | 333 |
hdr->d_compr = (uint8_t)ZZIP_GET16(d->z_compr); |
334 | 334 |
if (hdr->d_compr > 255) hdr->d_compr = 255; |
335 | 335 |
|
336 |
- if (offset+sizeof(*d) + u_namlen > u_rootsize) |
|
337 |
- |
|
338 |
- if (fd_map) |
|
339 |
- { memcpy(hdr->d_name, fd_map+fd_gap+offset+sizeof(*d), u_namlen); } |
|
340 |
- else { io->read(fd, hdr->d_name, u_namlen); } |
|
336 |
+ if (fd_map) |
|
337 |
+ { memcpy(hdr->d_name, fd_map+fd_gap+offset+sizeof(*d), u_namlen); } |
|
338 |
+ else |
|
339 |
+ { io->read(fd, hdr->d_name, u_namlen); } |
|
341 | 340 |
hdr->d_name[u_namlen] = '\0'; |
342 | 341 |
hdr->d_namlen = u_namlen; |
343 | 342 |
|
... | ... |
@@ -345,25 +275,26 @@ __zzip_parse_root_directory(int fd, |
345 | 345 |
offset += sizeof(*d) + u_namlen + u_extras + u_comment; |
346 | 346 |
|
347 | 347 |
if (offset > (long)u_rootsize) |
348 |
+ break; |
|
348 | 349 |
|
349 |
- |
|
350 | 350 |
p_reclen = &hdr->d_reclen; |
351 | 351 |
|
352 | 352 |
{ register char* p = (char*) hdr; |
353 | 353 |
register char* q = aligned4 (p + sizeof(*hdr) + u_namlen + 1); |
354 |
- *p_reclen = (uint16_t)(q - p); |
|
354 |
+ *p_reclen = q - p; |
|
355 | 355 |
hdr = (struct zzip_dir_hdr*) q; |
356 | 356 |
} |
357 | 357 |
}/*for*/ |
358 | 358 |
|
359 |
- if (p_reclen) |
|
360 |
- { |
|
361 |
- *p_reclen = 0; /* mark end of list */ |
|
359 |
+ if (!p_reclen) |
|
360 |
+ return 0; /* 0 (sane) entries in zip directory... */ |
|
362 | 361 |
|
363 |
- if (hdr_return) |
|
364 |
- *hdr_return = hdr0; |
|
365 |
- } /* else zero (sane) entries */ |
|
366 |
- return (entries ? ZZIP_CORRUPTED : 0); |
|
362 |
+ *p_reclen = 0; /* mark end of list */ |
|
363 |
+ |
|
364 |
+ if (hdr_return) |
|
365 |
+ *hdr_return = hdr0; |
|
366 |
+ |
|
367 |
+ return 0; |
|
367 | 368 |
} |
368 | 369 |
|
369 | 370 |
/* ------------------------- high-level interface ------------------------- */ |
... | ... |
@@ -520,6 +451,7 @@ __zzip_dir_parse (ZZIP_DIR* dir) |
520 | 520 |
dir->io)) != 0) |
521 | 521 |
{ goto error; } |
522 | 522 |
|
523 |
+ |
|
523 | 524 |
if ( (rv = __zzip_parse_root_directory(dir->fd, &trailer, &dir->hdr0, |
524 | 525 |
dir->io)) != 0) |
525 | 526 |
{ goto error; } |
... | ... |
@@ -538,7 +470,7 @@ __zzip_try_open(zzip_char_t* filename, int filemode, |
538 | 538 |
{ |
539 | 539 |
auto char file[PATH_MAX]; |
540 | 540 |
int fd; |
541 |
- zzip_size_t len = strlen (filename); |
|
541 |
+ int len = strlen (filename); |
|
542 | 542 |
|
543 | 543 |
if (len+4 >= PATH_MAX) return -1; |
544 | 544 |
memcpy(file, filename, len+1); |
... | ... |
@@ -75,9 +75,6 @@ ZZIP_DIR* |
75 | 75 |
zzip_dir_fdopen_ext_io(int fd, zzip_error_t * errorcode_p, |
76 | 76 |
zzip_strings_t* ext, const zzip_plugin_io_t io); |
77 | 77 |
|
78 |
-ZZIP_DIR* /*depracated*/ |
|
79 |
-zzip_dir_alloc_ext_io (zzip_strings_t* ext, const zzip_plugin_io_t io); |
|
80 |
- |
|
81 | 78 |
/* get 16/32 bits from little-endian zip-file to host byteorder */ |
82 | 79 |
uint32_t __zzip_get32(unsigned char * s); |
83 | 80 |
uint16_t __zzip_get16(unsigned char * s); |
... | ... |
@@ -3,17 +3,12 @@ |
3 | 3 |
* Guido Draheim <guidod@gmx.de> |
4 | 4 |
* Tomi Ollila <Tomi.Ollila@iki.fi> |
5 | 5 |
* |
6 |
- * Copyright (c) 1999,2000,2001,2002,2003 Guido Draheim |
|
6 |
+ * Copyright (c) 1999,2000,2001,2002 Guido Draheim |
|
7 | 7 |
* All rights reserved, |
8 | 8 |
* usage allowed under the restrictions of the |
9 | 9 |
* Lesser GNU General Public License |
10 | 10 |
* note the additional license information |
11 | 11 |
* that can be found in COPYING.ZZIP |
12 |
- * |
|
13 |
- * if you see "unknown symbol" errors, check first that `-I ..` is part of |
|
14 |
- * your compiler options - a special hint to VC/IDE users who tend to make up |
|
15 |
- * their own workspace files. All includes look like #include <zzip|*.h>, so |
|
16 |
- * you need to add an include path to the dir containing (!!) the ./zzip/ dir |
|
17 | 12 |
*/ |
18 | 13 |
|
19 | 14 |
#ifndef _ZZIP_ZZIP_H /* zziplib.h */ |
... | ... |
@@ -22,8 +17,6 @@ |
22 | 22 |
#include <zzip-conf.h> |
23 | 23 |
|
24 | 24 |
#include <fcntl.h> |
25 |
-#include <stddef.h> /* size_t and friends */ |
|
26 |
-/* msvc6 has neither ssize_t (we assume "int") nor off_t (assume "long") */ |
|
27 | 25 |
|
28 | 26 |
#ifdef __cplusplus |
29 | 27 |
extern "C" { |
... | ... |
@@ -79,8 +72,6 @@ typedef enum |
79 | 79 |
typedef char _zzip_const * _zzip_const zzip_strings_t; |
80 | 80 |
typedef char _zzip_const zzip_char_t; |
81 | 81 |
typedef _zzip_off_t zzip_off_t; |
82 |
-typedef _zzip_size_t zzip_size_t; |
|
83 |
-typedef _zzip_ssize_t zzip_ssize_t; |
|
84 | 82 |
typedef struct zzip_dir ZZIP_DIR; |
85 | 83 |
typedef struct zzip_file ZZIP_FILE; |
86 | 84 |
typedef struct zzip_dirent ZZIP_DIRENT; |
... | ... |
@@ -182,14 +173,14 @@ ZZIP_FILE * zzip_file_open(ZZIP_DIR * dir, zzip_char_t* name, int modes); |
182 | 182 |
_zzip_export |
183 | 183 |
int zzip_file_close(ZZIP_FILE * fp); |
184 | 184 |
_zzip_export |
185 |
-zzip_ssize_t zzip_file_read(ZZIP_FILE * fp, char* buf, zzip_size_t len); |
|
185 |
+int zzip_file_read(ZZIP_FILE * fp, char* buf, int len); |
|
186 | 186 |
|
187 | 187 |
_zzip_export |
188 | 188 |
ZZIP_FILE * zzip_open(zzip_char_t* name, int flags); |
189 | 189 |
_zzip_export |
190 | 190 |
int zzip_close(ZZIP_FILE * fp); |
191 | 191 |
_zzip_export |
192 |
-zzip_ssize_t zzip_read(ZZIP_FILE * fp, char * buf, zzip_size_t len); |
|
192 |
+int zzip_read(ZZIP_FILE * fp, char * buf, int len); |
|
193 | 193 |
|
194 | 194 |
|
195 | 195 |
_zzip_export |
... | ... |
@@ -197,8 +188,7 @@ ZZIP_FILE* zzip_freopen(zzip_char_t* name, zzip_char_t* mode, ZZIP_FILE*); |
197 | 197 |
_zzip_export |
198 | 198 |
ZZIP_FILE* zzip_fopen(zzip_char_t* name, zzip_char_t* mode); |
199 | 199 |
_zzip_export |
200 |
-zzip_size_t zzip_fread(void *ptr, zzip_size_t size, zzip_size_t nmemb, |
|
201 |
- ZZIP_FILE * file); |
|
200 |
+int zzip_fread(void *ptr, int size, int nmemb, ZZIP_FILE *file); |
|
202 | 201 |
_zzip_export |
203 | 202 |
int zzip_fclose(ZZIP_FILE * fp); |
204 | 203 |
|
... | ... |
@@ -208,9 +198,10 @@ int zzip_fclose(ZZIP_FILE * fp); |
208 | 208 |
_zzip_export |
209 | 209 |
int zzip_rewind(ZZIP_FILE *fp); |
210 | 210 |
_zzip_export |
211 |
-zzip_off_t zzip_seek(ZZIP_FILE * fp, zzip_off_t offset, int whence); |
|
211 |
+int zzip_seek(ZZIP_FILE * fp, int offset, int |
|
212 |
+ whence); |
|
212 | 213 |
_zzip_export |
213 |
-zzip_off_t zzip_tell(ZZIP_FILE * fp); |
|
214 |
+int zzip_tell(ZZIP_FILE * fp); |
|
214 | 215 |
|
215 | 216 |
|
216 | 217 |
/* |