Browse code

Don't loop if binhex runs out of memory

git-svn: trunk@2055

Nigel Horne authored on 2006/07/01 12:51:03
Showing 6 changed files
... ...
@@ -1,3 +1,9 @@
1
+Sat Jul  1 04:49:32 BST 2006 (njh)
2
+----------------------------------
3
+  * libclamav:	Large binhex files were not being handled gracefully. Tidied
4
+  			the handling code. Note that large binhex are not
5
+			currently decoded
6
+
1 7
 Thu Jun 29 19:42:01 CEST 2006 (acab)
2 8
   * libclamav: Revert old UPX code due to bugs
3 9
                Add algorithmic detection of Win32.Kriz
... ...
@@ -18,6 +18,9 @@
18 18
  *
19 19
  * Change History:
20 20
  * $Log: binhex.c,v $
21
+ * Revision 1.20  2006/07/01 03:47:50  njh
22
+ * Don't loop if binhex runs out of memory
23
+ *
21 24
  * Revision 1.19  2006/05/19 11:02:12  njh
22 25
  * Just include mbox.h
23 26
  *
... ...
@@ -73,7 +76,7 @@
73 73
  * First draft of binhex.c
74 74
  *
75 75
  */
76
-static	char	const	rcsid[] = "$Id: binhex.c,v 1.19 2006/05/19 11:02:12 njh Exp $";
76
+static	char	const	rcsid[] = "$Id: binhex.c,v 1.20 2006/07/01 03:47:50 njh Exp $";
77 77
 
78 78
 #include "clamav.h"
79 79
 
... ...
@@ -188,6 +191,8 @@ cli_binhex(const char *dir, int desc)
188 188
 		cli_errmsg("No binhex line found\n");
189 189
 		return CL_EFORMAT;
190 190
 	}
191
+	
192
+	/* similar to binhexMessage */
191 193
 	messageSetEncoding(m, "x-binhex");
192 194
 
193 195
 	fb = messageToFileblob(m, dir);
... ...
@@ -200,6 +205,6 @@ cli_binhex(const char *dir, int desc)
200 200
 
201 201
 	if(fb)
202 202
 		return CL_CLEAN;	/* a lie - but it gets things going */
203
-	return CL_EOPEN;
203
+	return CL_EIO;
204 204
 #endif
205 205
 }
... ...
@@ -16,7 +16,7 @@
16 16
  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17 17
  *  MA 02110-1301, USA.
18 18
  */
19
-static	char	const	rcsid[] = "$Id: blob.c,v 1.49 2006/06/08 10:13:12 njh Exp $";
19
+static	char	const	rcsid[] = "$Id: blob.c,v 1.50 2006/07/01 03:47:50 njh Exp $";
20 20
 
21 21
 #if HAVE_CONFIG_H
22 22
 #include "clamav-config.h"
... ...
@@ -297,14 +297,17 @@ blobcmp(const blob *b1, const blob *b2)
297 297
 	return memcmp(blobGetData(b1), blobGetData(b2), s1);
298 298
 }
299 299
 
300
-void
300
+/*
301
+ * Return clamav return code
302
+ */
303
+int
301 304
 blobGrow(blob *b, size_t len)
302 305
 {
303 306
 	assert(b != NULL);
304 307
 	assert(b->magic == BLOBCLASS);
305 308
 
306 309
 	if(len == 0)
307
-		return;
310
+		return CL_SUCCESS;
308 311
 
309 312
 	if(b->isClosed) {
310 313
 		/*
... ...
@@ -329,6 +332,8 @@ blobGrow(blob *b, size_t len)
329 329
 			b->data = ptr;
330 330
 		}
331 331
 	}
332
+
333
+	return (b->data) ? CL_SUCCESS : CL_EMEM;
332 334
 }
333 335
 
334 336
 fileblob *
... ...
@@ -44,7 +44,7 @@ unsigned char *blobGetData(const blob *b);
44 44
 unsigned	long	blobGetDataSize(const blob *b);
45 45
 void	blobClose(blob *b);
46 46
 int	blobcmp(const blob *b1, const blob *b2);
47
-void	blobGrow(blob *b, size_t len);
47
+int	blobGrow(blob *b, size_t len);
48 48
 
49 49
 /*
50 50
  * Like a blob, but associated with a file
... ...
@@ -16,7 +16,7 @@
16 16
  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17 17
  *  MA 02110-1301, USA.
18 18
  */
19
-static	char	const	rcsid[] = "$Id: message.c,v 1.175 2006/06/20 16:54:31 tkojm Exp $";
19
+static	char	const	rcsid[] = "$Id: message.c,v 1.176 2006/07/01 03:47:50 njh Exp $";
20 20
 
21 21
 #if HAVE_CONFIG_H
22 22
 #include "clamav-config.h"
... ...
@@ -1053,6 +1053,7 @@ messageExport(message *m, const char *dir, void *(*create)(void), void (*destroy
1053 1053
 		/* 70-7f */	0x3d,0x3e,0x3f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
1054 1054
 		};
1055 1055
 
1056
+		cli_dbgmsg("messageExport: decode binhex\n");
1056 1057
 		/*
1057 1058
 		 * Decode BinHex4. First create a temporary blob which contains
1058 1059
 		 * the encoded message. Then decode that blob to the target
... ...
@@ -17,6 +17,9 @@
17 17
  *  MA 02110-1301, USA.
18 18
  *
19 19
  * $Log: text.c,v $
20
+ * Revision 1.20  2006/07/01 03:47:50  njh
21
+ * Don't loop if binhex runs out of memory
22
+ *
20 23
  * Revision 1.19  2006/05/19 11:02:12  njh
21 24
  * Just include mbox.h
22 25
  *
... ...
@@ -67,7 +70,7 @@
67 67
  *
68 68
  */
69 69
 
70
-static	char	const	rcsid[] = "$Id: text.c,v 1.19 2006/05/19 11:02:12 njh Exp $";
70
+static	char	const	rcsid[] = "$Id: text.c,v 1.20 2006/07/01 03:47:50 njh Exp $";
71 71
 
72 72
 #if HAVE_CONFIG_H
73 73
 #include "clamav-config.h"
... ...
@@ -233,6 +236,7 @@ blob *
233 233
 textToBlob(const text *t, blob *b)
234 234
 {
235 235
 	size_t s;
236
+	blob *bin;
236 237
 
237 238
 	if(t == NULL)
238 239
 		return NULL;
... ...
@@ -251,7 +255,12 @@ textToBlob(const text *t, blob *b)
251 251
 			return NULL;
252 252
 	}
253 253
 
254
-	blobGrow(b, s);
254
+	bin = b;
255
+	if(blobGrow(b, s) != CL_SUCCESS) {
256
+		if(bin == NULL)
257
+			blobDestroy(b);
258
+		return NULL;
259
+	}
255 260
 
256 261
 	(void)textIterate(t, addToBlob, b);
257 262