Skip to content

Commit

Permalink
Merge pull request #952 from pi-hole/fix/case-insensitive_mac
Browse files Browse the repository at this point in the history
Use case-insensitive comparison for MAC addresses
  • Loading branch information
DL6ER authored Dec 2, 2020
2 parents c86107e + 01c36ef commit 9b1065e
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions src/database/network-table.c
Original file line number Diff line number Diff line change
Expand Up @@ -1160,17 +1160,7 @@ void parse_neighbor_cache(void)
// only the changed to the database are collected for latter
// commitment. Read-only access such as this SELECT command will be
// executed immediately on the database.
char *querystr = NULL;
rc = asprintf(&querystr, "SELECT id FROM network WHERE hwaddr = \'%s\';", hwaddr);
if(querystr == NULL || rc < 0)
{
logg("Memory allocation failed in parse_arp_cache(): %i", rc);
break;
}

// Perform SQL query
int dbID = db_query_int(querystr);
free(querystr);
int dbID = find_device_by_hwaddr(hwaddr);

if(dbID == DB_FAILED)
{
Expand Down Expand Up @@ -1392,19 +1382,19 @@ bool unify_hwaddr(void)

// Update firstSeen with lowest value across all rows with the same hwaddr
dbquery("UPDATE network "\
"SET firstSeen = (SELECT MIN(firstSeen) FROM network WHERE hwaddr = \'%s\') "\
"SET firstSeen = (SELECT MIN(firstSeen) FROM network WHERE hwaddr = \'%s\' COLLATE NOCASE) "\
"WHERE id = %i;",\
hwaddr, id);

// Update numQueries with sum of all rows with the same hwaddr
dbquery("UPDATE network "\
"SET numQueries = (SELECT SUM(numQueries) FROM network WHERE hwaddr = \'%s\') "\
"SET numQueries = (SELECT SUM(numQueries) FROM network WHERE hwaddr = \'%s\' COLLATE NOCASE) "\
"WHERE id = %i;",\
hwaddr, id);

// Remove all other lines with the same hwaddr but a different id
dbquery("DELETE FROM network "\
"WHERE hwaddr = \'%s\' "\
"WHERE hwaddr = \'%s\' COLLATE NOCASE "\
"AND id != %i;",\
hwaddr, id);

Expand Down

0 comments on commit 9b1065e

Please sign in to comment.