From d328befda020a2a33676df2ea60e12b642ad46db Mon Sep 17 00:00:00 2001 From: Tobias Waldekranz Date: Wed, 31 Aug 2022 14:59:45 +0200 Subject: [PATCH] Fix incorrect VID parsing of MDB entries Previous parser assumed that every entry had exactly one flag between the group and the VID, which is not always true. Move to a parser that is order independent and that ignores unknown fields. --- src/bridge.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/bridge.c b/src/bridge.c index bd4d123..2ca0ae8 100644 --- a/src/bridge.c +++ b/src/bridge.c @@ -98,10 +98,28 @@ static int populate(void) return -1; while (fgets(buf, sizeof(buf), fp)) { - char br[5], port[16], group[64], opt[10]; - int vid, n; + char br[5], port[16], group[64]; + char *tok, *dst; + int vid = 0; + + for (tok = strtok(buf, " \t"); tok; tok = strtok(NULL, " \t")) { + if (!strcmp(tok, "dev")) { + dst = br; + } else if (!strcmp(tok, "port")) { + dst = port; + } else if (!strcmp(tok, "grp")) { + dst = group; + } else if (!strcmp(tok, "vid")) { + tok = strtok(NULL, " \t"); + vid = strtol(tok, NULL, 10); + continue; + } else { + continue; + } - n = sscanf(buf, "dev %s port %s grp %s %s vid %d", br, port, group, opt, &vid); + tok = strtok(NULL, " \t"); + strcpy(dst, tok); + } /* XXX: Filter out IPv6 and MAC for now ... */ if (strchr(group, ':'))