Browse code

Recommit fix for bug 153

git-svn: trunk@2573

Nigel Horne authored on 2006/12/23 03:30:21
Showing 3 changed files
... ...
@@ -1,3 +1,8 @@
1
+Fri Dec 22 18:29:28 GMT 2006 (njh)
2
+----------------------------------
3
+  * libclamav/untar.[ch]:	Recommitting removed fix to bug 153
4
+				Needs a change to scanners.c
5
+
1 6
 Fri Dec 22 08:12:26 GMT 2006 (njh)
2 7
 ----------------------------------
3 8
   * libclamav/blob.c:	Escape tilde character on Windows (bug 207)
... ...
@@ -20,7 +20,7 @@
20 20
  * Author: Charles G. Waldman (cgw@pgt.com),  Aug 4 1998
21 21
  * There are many tar files that this code cannot decode.
22 22
  */
23
-static	char	const	rcsid[] = "$Id: untar.c,v 1.32 2006/10/15 11:10:42 njh Exp $";
23
+static	char	const	rcsid[] = "$Id: untar.c,v 1.33 2006/12/22 18:29:13 njh Exp $";
24 24
 
25 25
 #if HAVE_CONFIG_H
26 26
 #include "clamav-config.h"
... ...
@@ -61,10 +61,11 @@ octal(const char *str)
61 61
 }
62 62
 
63 63
 int
64
-cli_untar(const char *dir, int desc, unsigned int posix)
64
+cli_untar(const char *dir, int desc, unsigned int posix, const struct cl_limits *limits)
65 65
 {
66 66
 	int size = 0;
67 67
 	int in_block = 0;
68
+	unsigned int files = 0;
68 69
 	char fullname[NAME_MAX + 1];
69 70
 	FILE *outfile = NULL;
70 71
 
... ...
@@ -103,6 +104,11 @@ cli_untar(const char *dir, int desc, unsigned int posix)
103 103
 			if(block[0] == '\0')	/* We're done */
104 104
 				break;
105 105
 
106
+			if(limits && limits->maxfiles && (files >= limits->maxfiles)) {
107
+				cli_dbgmsg("cli_untar: number of files exceeded %u\n", limits->maxfiles);
108
+				return CL_CLEAN;
109
+			}
110
+
106 111
 			/* Notice assumption that BLOCKSIZE > 262 */
107 112
 			if(posix) {
108 113
 				strncpy(magic, block+257, 5);
... ...
@@ -122,6 +128,7 @@ cli_untar(const char *dir, int desc, unsigned int posix)
122 122
 				case '0':	/* plain file */
123 123
 				case '\0':	/* plain file */
124 124
 				case '7':	/* contiguous file */
125
+					files++;
125 126
 					directory = 0;
126 127
 					break;
127 128
 				case '1':	/* Link to already archived file */
... ...
@@ -173,10 +180,15 @@ cli_untar(const char *dir, int desc, unsigned int posix)
173 173
 				return CL_EFORMAT;
174 174
 			}
175 175
 			cli_dbgmsg("cli_untar: size = %d\n", size);
176
+			if(limits && limits->maxfilesize && ((unsigned int)size > limits->maxfilesize)) {
177
+				cli_dbgmsg("cli_untar: size exceeded %d bytes\n", size);
178
+				skipEntry++;
179
+			}
176 180
 
177 181
 			if(skipEntry) {
178 182
 				const int nskip = (size % BLOCKSIZE || !size) ? size + BLOCKSIZE - (size % BLOCKSIZE) : size;
179
-				cli_dbgmsg("cli_untar: GNU extension, skipping entry\n");
183
+
184
+				cli_dbgmsg("cli_untar: skipping entry\n");
180 185
 				lseek(desc, nskip, SEEK_CUR);
181 186
 				continue;
182 187
 			}
... ...
@@ -18,6 +18,9 @@
18 18
  *
19 19
  * Change History:
20 20
  * $Log: untar.h,v $
21
+ * Revision 1.5  2006/12/22 18:29:13  njh
22
+ * Recommit fix for bug 153
23
+ *
21 24
  * Revision 1.4  2006/04/09 19:59:28  kojm
22 25
  * update GPL headers with new address for FSF
23 26
  *
... ...
@@ -31,4 +34,4 @@
31 31
  * First draft
32 32
  *
33 33
  */
34
-int cli_untar(const char *dir, int desc, unsigned int posix);
34
+int cli_untar(const char *dir, int desc, unsigned int posix, const struct cl_limits *limits);