Skip to content

Commit f73957c

Browse files
committed
Prevent duplicate trusted mac, issue #145
1 parent f3276e6 commit f73957c

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

src/conf.c

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -874,15 +874,28 @@ void parse_trusted_mac_list(const char *ptr) {
874874
config.trustedmaclist->mac = safe_strdup(mac);
875875
config.trustedmaclist->next = NULL;
876876
} else {
877-
/* Advance to the last entry */
878-
p = config.trustedmaclist;
879-
while (p->next != NULL) {
880-
p = p->next;
881-
}
882-
p->next = safe_malloc(sizeof(t_trusted_mac));
883-
p = p->next;
884-
p->mac = safe_strdup(mac);
885-
p->next = NULL;
877+
int skipmac;
878+
/* Advance to the last entry */
879+
p = config.trustedmaclist;
880+
skipmac = 0;
881+
/* Check before loop to handle case were mac is a duplicate
882+
* of the first and only item in the list so far.
883+
*/
884+
if (0 == strcmp(p->mac, mac)) {
885+
skipmac = 1;
886+
}
887+
while (p->next != NULL) {
888+
if (0 == strcmp(p->mac, mac)) {
889+
skipmac = 1;
890+
}
891+
p = p->next;
892+
}
893+
if (!skipmac) {
894+
p->next = safe_malloc(sizeof(t_trusted_mac));
895+
p = p->next;
896+
p->mac = safe_strdup(mac);
897+
p->next = NULL;
898+
}
886899
}
887900
}
888901
}

0 commit comments

Comments
 (0)