]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MINOR] halog: skip non-traffic logs for -st and -tc
authorWilly Tarreau <w@1wt.eu>
Mon, 13 Sep 2010 20:50:49 +0000 (22:50 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 13 Sep 2010 20:50:49 +0000 (22:50 +0200)
Those were reporting stupid results in presence of administrative logs.

contrib/halog/halog.c

index ebdcfcfc4e3da396bd4f32f223cc016ea0274266..016227987cd65ec45faaa81a4f2bcc8f4f094d60 100644 (file)
@@ -603,7 +603,16 @@ int main(int argc, char **argv)
                }
 
                if (unlikely(filter & FILT_COUNT_STATUS)) {
-                       b = field_start(line, STATUS_FIELD + skip_fields);
+                       /* first, let's ensure that the line is a traffic line (beginning
+                        * with an IP address)
+                        */
+                       b = field_start(line, SOURCE_FIELD + skip_fields);
+                       if (*b < '0' || *b > '9') {
+                               parse_err++;
+                               continue;
+                       }
+
+                       b = field_start(b, STATUS_FIELD - SOURCE_FIELD + 1);
                        if (!*b) {
                                truncated_line(linenum, line);
                                continue;
@@ -616,7 +625,16 @@ int main(int argc, char **argv)
                }
 
                if (unlikely(filter & FILT_COUNT_TERM_CODES)) {
-                       b = field_start(line, TERM_CODES_FIELD + skip_fields);
+                       /* first, let's ensure that the line is a traffic line (beginning
+                        * with an IP address)
+                        */
+                       b = field_start(line, SOURCE_FIELD + skip_fields);
+                       if (*b < '0' || *b > '9') {
+                               parse_err++;
+                               continue;
+                       }
+
+                       b = field_start(b, TERM_CODES_FIELD - SOURCE_FIELD + 1);
                        if (!*b) {
                                truncated_line(linenum, line);
                                continue;