From: krw Date: Tue, 4 Apr 2017 13:01:20 +0000 (+0000) Subject: Treat SSID's like the 0 to 32 bytes of uint8_t data that they really X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=181376cfa6ae99a0f7ad07a3f4d74d967c845b99;p=openbsd Treat SSID's like the 0 to 32 bytes of uint8_t data that they really are. Track and use the actual lengths and use memcpy()/memcmp() instead of strcmp()/strdup(). --- diff --git a/sbin/dhclient/clparse.c b/sbin/dhclient/clparse.c index 7fbb674a7d6..a1bfc389138 100644 --- a/sbin/dhclient/clparse.c +++ b/sbin/dhclient/clparse.c @@ -1,4 +1,4 @@ -/* $OpenBSD: clparse.c,v 1.108 2017/04/03 19:59:39 krw Exp $ */ +/* $OpenBSD: clparse.c,v 1.109 2017/04/04 13:01:20 krw Exp $ */ /* Parser for dhclient config and lease files. */ @@ -505,7 +505,9 @@ parse_client_lease_statement(FILE *cfile, int is_static, TAILQ_FOREACH_SAFE(lp, &client->leases, next, pl) { if (lp->is_static != is_static) continue; - if (strcmp(lp->ssid, ifi->ssid) != 0) + if (lp->ssid_len != lease->ssid_len) + continue; + if (memcmp(lp->ssid, lease->ssid, lp->ssid_len) != 0) continue; if ((lease->options[DHO_DHCP_CLIENT_IDENTIFIER].len != 0) && ((lp->options[DHO_DHCP_CLIENT_IDENTIFIER].len != @@ -596,6 +598,7 @@ parse_client_lease_declaration(FILE *cfile, struct client_lease *lease, if (val && len <= sizeof(lease->ssid)) { memset(lease->ssid, 0, sizeof(lease->ssid)); memcpy(lease->ssid, val, len); + lease->ssid_len = len; } free(val); break; diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c index d1338a3033b..89bf3b5b5f9 100644 --- a/sbin/dhclient/dhclient.c +++ b/sbin/dhclient/dhclient.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dhclient.c,v 1.405 2017/03/08 20:54:30 krw Exp $ */ +/* $OpenBSD: dhclient.c,v 1.406 2017/04/04 13:01:20 krw Exp $ */ /* * Copyright 2004 Henning Brauer @@ -526,6 +526,7 @@ main(int argc, char *argv[]) if (ioctl(sock, SIOCG80211NWID, (caddr_t)&ifr) == 0) { memset(ifi->ssid, 0, sizeof(ifi->ssid)); memcpy(ifi->ssid, nwid.i_nwid, nwid.i_len); + ifi->ssid_len = nwid.i_len; } /* Put us into the correct rdomain */ @@ -775,7 +776,9 @@ state_reboot(void *xifi) /* Run through the list of leases and see if one can be used. */ i = DHO_DHCP_CLIENT_IDENTIFIER; TAILQ_FOREACH(lp, &client->leases, next) { - if (strcmp(lp->ssid, ifi->ssid) != 0) + if (lp->ssid_len != ifi->ssid_len) + continue; + if (memcmp(lp->ssid, ifi->ssid, lp->ssid_len) != 0) continue; if ((lp->options[i].len != 0) && ((lp->options[i].len != config->send_options[i].len) || @@ -957,6 +960,7 @@ dhcpack(struct interface_info *ifi, struct in_addr client_addr, client->new = lease; memcpy(client->new->ssid, ifi->ssid, sizeof(client->new->ssid)); + client->new->ssid_len = ifi->ssid_len; /* Stop resending DHCPREQUEST. */ cancel_timeout(); @@ -1086,8 +1090,12 @@ newlease: TAILQ_FOREACH_SAFE(lease, &client->leases, next, pl) { if (lease->is_static) break; - if (client->active && strcmp(client->active->ssid, - lease->ssid) != 0) + if (client->active == NULL) + continue; + if (client->active->ssid_len != lease->ssid_len) + continue; + if (memcmp(client->active->ssid, lease->ssid, lease->ssid_len) + != 0) continue; if (client->active == lease) seen = 1; @@ -1489,7 +1497,9 @@ state_panic(void *xifi) /* Run through the list of leases and see if one can be used. */ time(&cur_time); TAILQ_FOREACH(lp, &client->leases, next) { - if (strcmp(lp->ssid, ifi->ssid) != 0) + if (lp->ssid_len != ifi->ssid_len) + continue; + if (memcmp(lp->ssid, ifi->ssid, lp->ssid_len) != 0) continue; if (addressinuse(ifi, lp->address, ifname) && strncmp(ifname, ifi->name, IF_NAMESIZE) != 0) @@ -1999,14 +2009,14 @@ lease_as_string(struct interface_info *ifi, char *type, p += rslt; sz -= rslt; } - if (strlen(lease->ssid)) { + if (lease->ssid_len != 0) { rslt = snprintf(p, sz, " ssid "); if (rslt == -1 || rslt >= sz) return (NULL); p += rslt; sz -= rslt; rslt = pretty_print_string(p, sz, lease->ssid, - strlen(lease->ssid), 1); + lease->ssid_len, 1); if (rslt == -1 || rslt >= sz) return (NULL); p += rslt; @@ -2463,6 +2473,7 @@ clone_lease(struct client_lease *oldlease) newlease->address = oldlease->address; newlease->next_server = oldlease->next_server; memcpy(newlease->ssid, oldlease->ssid, sizeof(newlease->ssid)); + newlease->ssid_len = oldlease->ssid_len; if (oldlease->server_name) { newlease->server_name = strdup(oldlease->server_name); diff --git a/sbin/dhclient/dhcpd.h b/sbin/dhclient/dhcpd.h index ff24cc48f49..f599a6df629 100644 --- a/sbin/dhclient/dhcpd.h +++ b/sbin/dhclient/dhcpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dhcpd.h,v 1.162 2017/04/03 19:59:39 krw Exp $ */ +/* $OpenBSD: dhcpd.h,v 1.163 2017/04/04 13:01:20 krw Exp $ */ /* * Copyright (c) 2004 Henning Brauer @@ -69,7 +69,8 @@ struct client_lease { char *server_name; char *filename; char *resolv_conf; - char ssid[33]; + char ssid[32]; + uint8_t ssid_len; unsigned int is_static; unsigned int is_bootp; unsigned int is_invalid; @@ -144,7 +145,8 @@ struct client_state { struct interface_info { struct ether_addr hw_address; char name[IFNAMSIZ]; - char ssid[33]; + char ssid[32]; + uint8_t ssid_len; struct client_state *client; int bfdesc; /* bpf - reading & broadcast writing*/ int ufdesc; /* udp - unicast writing */