Skip to content

Commit

Permalink
Fix incorrect VID parsing of MDB entries
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
wkz committed Aug 31, 2022
1 parent fffd4c2 commit d328bef
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/bridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -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, ':'))
Expand Down

0 comments on commit d328bef

Please sign in to comment.