[Pkg-clamav-commits] [SCM] Debian repository for ClamAV branch, debian/unstable, updated. debian/0.95+dfsg-1-6156-g094ec9b

aCaB acab at clamav.net
Sun Apr 4 01:07:14 UTC 2010


The following commit has been merged in the debian/unstable branch:
commit 6bcd0c866f91ce5b6e4a3db704407542f12bc30b
Author: aCaB <acab at clamav.net>
Date:   Thu Oct 8 20:28:58 2009 +0200

    fix getline in mbox

diff --git a/libclamav/mbox.c b/libclamav/mbox.c
index de48063..55823c5 100644
--- a/libclamav/mbox.c
+++ b/libclamav/mbox.c
@@ -3261,12 +3261,12 @@ usefulHeader(int commandNumber, const char *cmd)
  * Like fgets but cope with end of line by "\n", "\r\n", "\n\r", "\r"
  */
 static char *
-getline_from_mbox(char *buffer, size_t len, fmap_t *map, size_t *at)
+getline_from_mbox(char *buffer, size_t buffer_len, fmap_t *map, size_t *at)
 {
     char *src, *cursrc, *curbuf;
     size_t i;
-    len = MIN(map->len - *at, len);
-    src = cursrc = fmap_need_off_once(map, *at, len);
+    size_t input_len = MIN(map->len - *at, buffer_len + 1);
+    src = cursrc = fmap_need_off_once(map, *at, input_len);
 
 /*	we check for eof from the result of GETC()
  *	if(feof(fin)) 
@@ -3275,27 +3275,37 @@ getline_from_mbox(char *buffer, size_t len, fmap_t *map, size_t *at)
 	cli_dbgmsg("getline_from_mbox: fmap need failed\n");
 	return NULL;
     }
-    if((len == 0) || (buffer == NULL)) {
+    if((buffer_len == 0) || (buffer == NULL)) {
 	cli_errmsg("Invalid call to getline_from_mbox(). Refer to http://www.clamav.net/bugs\n");
 	return NULL;
     }
+
     curbuf = buffer;
 	
-    for(i=0; i<len; i++) {
-	char c = *cursrc++;
-	switch(c) {
+    for(i=0; i<buffer_len-1; i++) {
+	char c;
+
+	if(!input_len--) {
+	    if(curbuf == buffer) {
+		/* EOF on first char */
+		return NULL;
+	    }
+	    break;
+	}
+
+	switch((c = *cursrc++)) {
 	case '\0':
 	    continue;
 	case '\n':
 	    *curbuf++ = '\n';
-	    if(i != len-1 && *cursrc == '\r') {
+	    if(input_len && *cursrc == '\r') {
 		i++;
 		cursrc++;
 	    }
 	    break;
 	case '\r':
 	    *curbuf++ = '\r';
-	    if(i != len-1 && *cursrc == '\n') {
+	    if(input_len && *cursrc == '\n') {
 		i++;
 		cursrc++;
 	    }
@@ -3307,11 +3317,6 @@ getline_from_mbox(char *buffer, size_t len, fmap_t *map, size_t *at)
 	break;
     }
     *at += cursrc - src;
-    if(i == len) {
-	/* the email probably breaks RFC821 */
-	cli_dbgmsg("getline_from_mbox: buffer overflow stopped, line lost\n");
-	return NULL;
-    }
     *curbuf = '\0';
     
     return buffer;

-- 
Debian repository for ClamAV



More information about the Pkg-clamav-commits mailing list