Package: mergelog
Version: 4.5.1-9
Severity: normal
Tags: ipv6 patch upstream

Dear Maintainer,

Mergelog fails to merge lines where there is an IPv6 in brackets before
the date field with the following message:

problem with ...logfile:
2001:1be0:1000:169:250:56ff:fe92:4eb6 [2a02:2178:0002:000c:0000:0000:0000:0013] 
- [13/Mar/2016:17:45:39 +0100] "GET / HTTP/1.1" 200 133845 "-" "Mozilla/5.0 
(compatible; oBot/2.3.1; http://filterdb.iss.net/crawler/)"

continuing...

This is because mergelog considers that the first string between brackets
must be the date field, which is wrong.

Attached is a patch which continues to the next field with brackets if the
date parsing failed until there is not more field with brackets instead
of only considering the first one.

Sylvain

-- System Information:
Debian Release: stretch/sid
  APT prefers stable-updates
  APT policy: (500, 'stable-updates'), (500, 'oldstable-updates'), (500, 
'unstable'), (500, 'stable'), (500, 'oldstable')
Architecture: amd64 (x86_64)

Kernel: Linux 4.3.0-1-amd64 (SMP w/4 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: unable to detect

Versions of packages mergelog depends on:
ii  libc6   2.21-9
ii  zlib1g  1:1.2.8.dfsg-2+b1

mergelog recommends no packages.

mergelog suggests no packages.

-- no debconf information
diff -Nru a/src/mergelog.c b/src/mergelog.c
--- a/src/mergelog.c	2001-11-05 15:47:49.000000000 +0000
+++ b/src/mergelog.c	2016-03-15 22:17:05.488900070 +0000
@@ -222,31 +222,35 @@
      */
     if (mygets(log_buffer[i],BUFFER_SIZE,log_file[i],i) != NULL ) {
 
-      /*
-	get the date pointers
-      */
-      log_date=memchr(log_scan[i],'[',SCAN_SIZE);
-      if (log_date == NULL) {
-	fprintf(stderr,"abort due to a problem with %s:\n%s\n",argv[i+1],log_buffer[i]);
-	exit(1);
-      }
-      
-      /*
-	put the date in the tmp_date_buf
-       */
-       for (j=0;((j == 12)&&(memcmp(months+2*j,log_date+5,2) != 0));j++);
-       if (j == 12) {
-	 fprintf(stderr,"abort due to a problem with %s:\n%s\n",argv[i+1],log_buffer[i]);
-	 exit(1);
+      int off=0;
+      for (;;) {
+        /*
+	  get the date pointers
+        */
+        log_date=memchr(log_scan[i]+off,'[',SCAN_SIZE-off);
+        if (log_date == NULL) {
+	  fprintf(stderr,"abort due to a problem with %s:\n%s\n",argv[i+1],log_buffer[i]);
+	  exit(1);
+        }
+        
+        /*
+	  put the date in the tmp_date_buf
+         */
+         for (j=0;((j<12)&&(memcmp(months+2*j,log_date+5,2) != 0));j++);
+         if (j == 12) {
+	   off=log_date-log_scan[i]+1;
+	   continue;
+         }
+         memcpy(log_month[i],trans_digits[j],2);
+         memcpy(log_month[i]+2,months+2*j,2);
+         memcpy(tmp_date_buf[i],log_date+8,4);
+         memcpy(tmp_date_buf[i]+4,trans_digits[j],2);
+         memcpy(tmp_date_buf[i]+6,log_date+1,2);
+         memcpy(tmp_date_buf[i]+8,log_date+13,2);
+         memcpy(tmp_date_buf[i]+10,log_date+16,2);
+         memcpy(tmp_date_buf[i]+12,log_date+19,2);
+         break;
        }
-       memcpy(log_month[i],trans_digits[j],2);
-       memcpy(log_month[i]+2,months+2*j,2);
-       memcpy(tmp_date_buf[i],log_date+8,4);
-       memcpy(tmp_date_buf[i]+4,trans_digits[j],2);
-       memcpy(tmp_date_buf[i]+6,log_date+1,2);
-       memcpy(tmp_date_buf[i]+8,log_date+13,2);
-       memcpy(tmp_date_buf[i]+10,log_date+16,2);
-       memcpy(tmp_date_buf[i]+12,log_date+19,2);
 
       /*
 	extract the date of this first line
@@ -399,12 +403,16 @@
 	  *(tmp_date_buf[i])='9';
           break;
 	} else {
-
-	  /*
-	    prepare the new pointer for the date test
-	   */
-	  log_date=memchr(log_scan[i],'[',SCAN_SIZE);
-	  if (log_date != NULL) {
+          int off=0;
+          for (;;) {
+	    /*
+	      prepare the new pointer for the date test
+	     */
+	    log_date=memchr(log_scan[i]+off,'[',SCAN_SIZE-off);
+	    if (log_date == NULL) {
+	      fprintf(stderr,"problem with %s:\n%s\ncontinuing...\n",argv[i+1],log_buffer[i]);
+	      break;
+	    }
 
 	    /*
 	      convert the log line month if necessary
@@ -418,26 +426,26 @@
 	      memcpy(tmp_date_buf[i]+8,log_date+13,2);
 	      memcpy(tmp_date_buf[i]+10,log_date+16,2);
 	      memcpy(tmp_date_buf[i]+12,log_date+19,2);
+              break;
+	    }
 
-	    } else {
-	      for (j=0;((j<12)&&(memcmp(months+2*j,log_date+5,2) != 0));j++);
-	      if (j == 12) {
-		fprintf(stderr,"problem with %s:\n%s\ncontinuing...\n",argv[i+1],log_buffer[i]);
-	      } else {
-		memcpy(log_month[i],trans_digits[j],2);
-		memcpy(log_month[i]+2,months+2*j,2);
-		memcpy(tmp_date_buf[i]+4,trans_digits[j],2);
-		
-		memcpy(tmp_date_buf[i],log_date+8,4);
-		memcpy(tmp_date_buf[i]+6,log_date+1,2);
-		memcpy(tmp_date_buf[i]+8,log_date+13,2);
-		memcpy(tmp_date_buf[i]+10,log_date+16,2);
-		memcpy(tmp_date_buf[i]+12,log_date+19,2);
-	      }
+	    for (j=0;((j<12)&&(memcmp(months+2*j,log_date+5,2) != 0));j++);
+	    if (j == 12) {
+	      off=log_date-log_scan[i]+1;
+	      continue;
 	    }
-	  } else {
-	    fprintf(stderr,"problem with %s:\n%s\ncontinuing...\n",argv[i+1],log_buffer[i]);
-	  }
+
+	    memcpy(log_month[i],trans_digits[j],2);
+	    memcpy(log_month[i]+2,months+2*j,2);
+	    memcpy(tmp_date_buf[i]+4,trans_digits[j],2);
+		
+	    memcpy(tmp_date_buf[i],log_date+8,4);
+	    memcpy(tmp_date_buf[i]+6,log_date+1,2);
+	    memcpy(tmp_date_buf[i]+8,log_date+13,2);
+	    memcpy(tmp_date_buf[i]+10,log_date+16,2);
+	    memcpy(tmp_date_buf[i]+12,log_date+19,2);
+	    break;
+          }
 	}
       }
     }

Reply via email to