Browse code

Fix logic error in blobClose

git-svn-id: file:///var/lib/svn/clamav-devel/trunk/clamav-devel@571 77e5149b-7576-45b1-b177-96237e5ba77b

Nigel Horne authored on 2004/05/21 20:33:43
Showing 2 changed files
... ...
@@ -1,7 +1,11 @@
1
+Fri May 21 12:32:24 BST 2004 (njh)
2
+----------------------------------
3
+  * libclamav/blob.c:	Fixed logic error in blobClose()
4
+
1 5
 Fri May 21 10:16:27 BST 2004 (njh)
2 6
 ----------------------------------
3 7
   * clamav-milter:	--from wasn't always recognised
4
-  			write failures to quarantine area were not correctly
8
+			write failures to quarantine area were not correctly
5 9
 	reported
6 10
 
7 11
 Thu May 20 11:23:23 BST 2004 (trog)
... ...
@@ -11,7 +15,7 @@ Thu May 20 11:23:23 BST 2004 (trog)
11 11
 Wed May 19 11:02:53 BST 2004 (njh)
12 12
 ---------------------------------
13 13
   * libclamav/message.c:	Assume attachments which don't declare how
14
-  	they've been encoded are base64
14
+	they've been encoded are base64
15 15
 
16 16
 Wed May 19 09:10:12 BST 2004 (trog)
17 17
 -----------------------------------
... ...
@@ -71,7 +75,7 @@ Tue May 11 02:07:55 CEST 2004 (tk)
71 71
 Mon May 10 12:25:09 BST 2004 (njh)
72 72
 ----------------------------------
73 73
   * libclamav:		Don't call cli_filetype() so often since the latest
74
-  		chanves give false positives about the start of bounce messages
74
+		chanves give false positives about the start of bounce messages
75 75
 		which opens up DoS attacks, and allows worms hidden in bounce
76 76
 		messages to be hidden with ease
77 77
 
... ...
@@ -101,7 +105,7 @@ Sun May  9 18:40:55 BST 2004 (njh)
101 101
 			Also added X-Infected-Received-From: header by Sergey
102 102
 			Report an error if inet_ntop fails in tcp_wrappers
103 103
  * docs/man:		Clarified suggested use of max-children only on
104
- 		small machines
104
+		small machines
105 105
 
106 106
 Fri May  7 19:46:05 CEST 2004 (tk)
107 107
 ----------------------------------
... ...
@@ -16,6 +16,9 @@
16 16
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 17
  *
18 18
  * $Log: blob.c,v $
19
+ * Revision 1.12  2004/05/21 11:31:48  nigelhorne
20
+ * Fix logic error in blobClose
21
+ *
19 22
  * Revision 1.11  2004/04/17 14:18:58  nigelhorne
20 23
  * Some filenames not scanned in MACOS/X
21 24
  *
... ...
@@ -35,7 +38,7 @@
35 35
  * Change LOG to Log
36 36
  *
37 37
  */
38
-static	char	const	rcsid[] = "$Id: blob.c,v 1.11 2004/04/17 14:18:58 nigelhorne Exp $";
38
+static	char	const	rcsid[] = "$Id: blob.c,v 1.12 2004/05/21 11:31:48 nigelhorne Exp $";
39 39
 
40 40
 #if HAVE_CONFIG_H
41 41
 #include "clamav-config.h"
... ...
@@ -107,8 +110,6 @@ blobArrayDestroy(blob *blobList[], int n)
107 107
 void
108 108
 blobSetFilename(blob *b, const char *filename)
109 109
 {
110
-	char *ptr;
111
-
112 110
 	assert(b != NULL);
113 111
 	assert(b->magic == BLOB);
114 112
 	assert(filename != NULL);
... ...
@@ -117,7 +118,9 @@ blobSetFilename(blob *b, const char *filename)
117 117
 		free(b->name);
118 118
 	b->name = strdup(filename);
119 119
 
120
-	if(b->name)
120
+	if(b->name) {
121
+		char *ptr;
122
+
121 123
 		for(ptr = b->name; *ptr; ptr++) {
122 124
 #if	defined(MSDOS) || defined(C_CYGWIN) || defined(WIN32)
123 125
 			if(strchr("*?<>|\"+=,;: ", *ptr))
... ...
@@ -128,6 +131,7 @@ blobSetFilename(blob *b, const char *filename)
128 128
 #endif
129 129
 				*ptr = '_';
130 130
 		}
131
+	}
131 132
 
132 133
 	cli_dbgmsg("blobSetFilename: %s\n", filename);
133 134
 }
... ...
@@ -197,12 +201,15 @@ blobGetDataSize(const blob *b)
197 197
 void
198 198
 blobClose(blob *b)
199 199
 {
200
-	b->isClosed = 1;
200
+	if(b->size > b->len) {
201
+		unsigned char *ptr = cli_realloc(b->data, b->len);
201 202
 
202
-	if(b->size != b->len) {
203
+		if(ptr == NULL)
204
+			return;
203 205
 		b->size = b->len;
204
-		b->data = cli_realloc(b->data, b->size);
206
+		b->data = ptr;
205 207
 	}
208
+	b->isClosed = 1;
206 209
 }
207 210
 
208 211
 /*
... ...
@@ -249,10 +256,15 @@ blobGrow(blob *b, size_t len)
249 249
 		assert(b->len == 0);
250 250
 		assert(b->size == 0);
251 251
 
252
-		b->size = len;
253 252
 		b->data = cli_malloc(len);
253
+		if(b->data)
254
+			b->size = len;
254 255
 	} else {
255
-		b->size += len;
256
-		b->data = cli_realloc(b->data, b->size);
256
+		unsigned char *ptr = cli_realloc(b->data, b->size + len);
257
+
258
+		if(ptr) {
259
+			b->size += len;
260
+			b->data = ptr;
261
+		}
257 262
 	}
258 263
 }