]> rtime.felk.cvut.cz Git - sojka/can-utils.git/commitdiff
Added support for comments in logfiles.
authorOliver Hartkopp <socketcan@hartkopp.net>
Tue, 9 Sep 2008 12:56:05 +0000 (12:56 +0000)
committerOliver Hartkopp <socketcan@hartkopp.net>
Tue, 9 Sep 2008 12:56:05 +0000 (12:56 +0000)
Added some sanity checks and error messages.

log2asc.c

index f26b3a385df854e0bc6feb45642bfde8fc120f72..380990fd994ba3c270f9bfc3447f5c74de4aa1a0 100644 (file)
--- a/log2asc.c
+++ b/log2asc.c
@@ -56,6 +56,8 @@
 
 #include "lib.h"
 
+#define BUFSZ 400 /* for one line in the logfile */
+
 extern int optind, opterr, optopt;
 
 void print_usage(char *prg)
@@ -69,7 +71,7 @@ void print_usage(char *prg)
 
 int main(int argc, char **argv)
 {
-       char buf[100], device[100], ascframe[100], id[10];
+       static char buf[BUFSZ], device[BUFSZ], ascframe[BUFSZ], id[10];
 
        struct can_frame cf;
        static struct timeval tv, start_tv;
@@ -121,10 +123,22 @@ int main(int argc, char **argv)
        
        //printf("Found %d CAN devices!\n", maxdev);
 
-       while (fgets(buf, 99, infile)) {
+       while (fgets(buf, BUFSZ-1, infile)) {
+
+               if (strlen(buf) >= BUFSZ-2) {
+                       fprintf(stderr, "line too long for input buffer\n");
+                       return 1;
+               }
+
+               /* check for a comment line */
+               if (buf[0] != '(')
+                       continue;
+
                if (sscanf(buf, "(%ld.%ld) %s %s", &tv.tv_sec, &tv.tv_usec,
-                          device, ascframe) != 4)
+                          device, ascframe) != 4) {
+                       fprintf(stderr, "incorrect line format in logfile\n");
                        return 1;
+               }
 
                if (!start_tv.tv_sec) { /* print banner */
                        start_tv = tv;