From cf20398d32e29fe7dc6609a5d49cd4ac00af9267 Mon Sep 17 00:00:00 2001 From: Jiho Chu Date: Sat, 14 Jan 2017 20:15:40 +0100 Subject: [PATCH] bcmserver: allow CAN netdevice names greater than 6 characters 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 Signed-off-by: Oliver Hartkopp --- bcmserver.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/bcmserver.c b/bcmserver.c index 39aefef..f16052a 100644 --- a/bcmserver.c +++ b/bcmserver.c @@ -126,6 +126,7 @@ #include #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, -- 2.7.4