Browse code

Better handling of full disc

git-svn: trunk@1452

Nigel Horne authored on 2005/04/04 22:52:46
Showing 3 changed files
... ...
@@ -15,7 +15,7 @@
15 15
  *  along with this program; if not, write to the Free Software
16 16
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 17
  */
18
-static	char	const	rcsid[] = "$Id: blob.c,v 1.39 2005/03/20 09:09:25 nigelhorne Exp $";
18
+static	char	const	rcsid[] = "$Id: blob.c,v 1.40 2005/04/04 13:52:46 nigelhorne Exp $";
19 19
 
20 20
 #if HAVE_CONFIG_H
21 21
 #include "clamav-config.h"
... ...
@@ -129,7 +129,7 @@ blobGetFilename(const blob *b)
129 129
 	return b->name;
130 130
 }
131 131
 
132
-void
132
+int
133 133
 blobAddData(blob *b, const unsigned char *data, size_t len)
134 134
 {
135 135
 #ifdef	HAVE_GETPAGESIZE
... ...
@@ -142,7 +142,7 @@ blobAddData(blob *b, const unsigned char *data, size_t len)
142 142
 	assert(data != NULL);
143 143
 
144 144
 	if(len == 0)
145
-		return;
145
+		return 0;
146 146
 
147 147
 	if(b->isClosed) {
148 148
 		/*
... ...
@@ -183,7 +183,7 @@ blobAddData(blob *b, const unsigned char *data, size_t len)
183 183
 		unsigned char *p = cli_realloc(b->data, b->size + growth);
184 184
 
185 185
 		if(p == NULL)
186
-			return;
186
+			return -1;
187 187
 
188 188
 		b->size += growth;
189 189
 		b->data = p;
... ...
@@ -199,7 +199,7 @@ blobAddData(blob *b, const unsigned char *data, size_t len)
199 199
 		unsigned char *p = cli_realloc(b->data, b->size + (len * 4));
200 200
 
201 201
 		if(p == NULL)
202
-			return;
202
+			return -1;
203 203
 
204 204
 		b->size += len * 4;
205 205
 		b->data = p;
... ...
@@ -210,6 +210,7 @@ blobAddData(blob *b, const unsigned char *data, size_t len)
210 210
 		memcpy(&b->data[b->len], data, len);
211 211
 		b->len += len;
212 212
 	}
213
+	return 0;
213 214
 }
214 215
 
215 216
 unsigned char *
... ...
@@ -432,7 +433,7 @@ fileblobSetFilename(fileblob *fb, const char *dir, const char *filename)
432 432
 	}
433 433
 	if(fb->b.data) {
434 434
 		if(fwrite(fb->b.data, fb->b.len, 1, fb->fp) != 1)
435
-			cli_errmsg("fileblobSetFilename: Can't write to temporary file %s: %s\n", fb->b.name, strerror(errno));
435
+			cli_errmsg("fileblobSetFilename: Can't write to temporary file %s: %s\n", fullname, strerror(errno));
436 436
 		else
437 437
 			fb->isNotEmpty = 1;
438 438
 		free(fb->b.data);
... ...
@@ -441,21 +442,23 @@ fileblobSetFilename(fileblob *fb, const char *dir, const char *filename)
441 441
 	}
442 442
 }
443 443
 
444
-void
444
+int
445 445
 fileblobAddData(fileblob *fb, const unsigned char *data, size_t len)
446 446
 {
447 447
 	if(len == 0)
448
-		return;
448
+		return 0;
449 449
 
450 450
 	assert(data != NULL);
451 451
 
452 452
 	if(fb->fp) {
453
-		if(fwrite(data, len, 1, fb->fp) != 1)
453
+		if(fwrite(data, len, 1, fb->fp) != 1) {
454 454
 			cli_errmsg("fileblobAddData: Can't write %u bytes to temporary file %s: %s\n", len, fb->b.name, strerror(errno));
455
-		else
456
-			fb->isNotEmpty = 1;
457
-	} else
458
-		blobAddData(&(fb->b), data, len);
455
+			return -1;
456
+		}
457
+		fb->isNotEmpty = 1;
458
+		return 0;
459
+	}
460
+	return blobAddData(&(fb->b), data, len);
459 461
 }
460 462
 
461 463
 const char *
... ...
@@ -40,7 +40,7 @@ void	blobDestroy(blob *b);
40 40
 void	blobArrayDestroy(blob *b[], int n);
41 41
 void	blobSetFilename(blob *b, const char *dir, const char *filename);
42 42
 const	char	*blobGetFilename(const blob *b);
43
-void	blobAddData(blob *b, const unsigned char *data, size_t len);
43
+int	blobAddData(blob *b, const unsigned char *data, size_t len);
44 44
 unsigned char *blobGetData(const blob *b);
45 45
 unsigned	long	blobGetDataSize(const blob *b);
46 46
 void	blobClose(blob *b);
... ...
@@ -60,7 +60,7 @@ fileblob	*fileblobCreate(void);
60 60
 void	fileblobDestroy(fileblob *fb);
61 61
 void	fileblobSetFilename(fileblob *fb, const char *dir, const char *filename);
62 62
 const	char	*fileblobGetFilename(const fileblob *fb);
63
-void	fileblobAddData(fileblob *fb, const unsigned char *data, size_t len);
63
+int	fileblobAddData(fileblob *fb, const unsigned char *data, size_t len);
64 64
 void	sanitiseName(char *name);
65 65
 
66 66
 /* Maximum filenames under various systems */
... ...
@@ -15,7 +15,7 @@
15 15
  *  along with this program; if not, write to the Free Software
16 16
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 17
  */
18
-static	char	const	rcsid[] = "$Id: mbox.c,v 1.234 2005/04/02 21:18:48 nigelhorne Exp $";
18
+static	char	const	rcsid[] = "$Id: mbox.c,v 1.235 2005/04/04 13:52:46 nigelhorne Exp $";
19 19
 
20 20
 #if HAVE_CONFIG_H
21 21
 #include "clamav-config.h"
... ...
@@ -3823,7 +3823,8 @@ uufasttrack(message *m, const char *firstline, const char *dir, FILE *fin)
3823 3823
 		if((len > 62) || (len == 0))
3824 3824
 			break;
3825 3825
 
3826
-		fileblobAddData(fb, data, len);
3826
+		if(fileblobAddData(fb, data, len) < 0)
3827
+			break;
3827 3828
 	}
3828 3829
 
3829 3830
 	fileblobDestroy(fb);