bcmserver: allow CAN netdevice names greater than 6 characters 46/113046/1 tizen_3.0
authorJiho Chu <jiho.chu@samsung.com>
Sat, 14 Jan 2017 19:15:40 +0000 (20:15 +0100)
committerJiho Chu <jiho.chu@samsung.com>
Mon, 6 Feb 2017 00:58:18 +0000 (09:58 +0900)
The sscanf() function to parse bcmserver command strings limited the length of
the CAN netdevice name to six characters. With this patch the length is derived
from the IFNAMSIZ which defines the space in ifr.ifr_name.

Change-Id: I80d9988d75abc3014fdc3837afbf11a4769ddddc
Signed-off-by: Jiho Chu <jiho.chu@samsung.com>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
bcmserver.c

index 39aefef..f16052a 100644 (file)
 #include <linux/can/bcm.h>
 
 #define MAXLEN 100
+#define FORMATSZ 80
 #define PORT 28600
 
 void childdied(int i)
@@ -149,6 +150,7 @@ int main(int argc, char **argv)
        sigset_t sigset;
 
        char buf[MAXLEN];
+       char format[FORMATSZ];
        char rxmsg[50];
 
        struct {
@@ -156,6 +158,11 @@ int main(int argc, char **argv)
                struct can_frame frame;
        } msg;
 
+       if (snprintf(format, FORMATSZ, "< %%%ds %%c %%lu %%lu %%x %%hhu "
+                    "%%hhx %%hhx %%hhx %%hhx %%hhx %%hhx "
+                    "%%hhx %%hhx >", IFNAMSIZ-1) >= FORMATSZ-1)
+               exit(1);
+
        sigemptyset(&sigset);
        signalaction.sa_handler = &childdied;
        signalaction.sa_mask = sigset;
@@ -282,9 +289,7 @@ int main(int argc, char **argv)
                        memset(&msg, 0, sizeof(msg));
                        msg.msg_head.nframes = 1;
 
-                       items = sscanf(buf, "< %6s %c %lu %lu %x %hhu "
-                                      "%hhx %hhx %hhx %hhx %hhx %hhx "
-                                      "%hhx %hhx >",
+                       items = sscanf(buf, format,
                                       ifr.ifr_name,
                                       &cmd, 
                                       &msg.msg_head.ival2.tv_sec,