diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2013-01-16 21:35:42 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2013-01-16 21:35:42 +0000 |
commit | 3a2228f57f033ec5c5d00c4d129cdbff5003c5a0 (patch) | |
tree | 3089731a64b8a95dc146e0dae945627977166a9e /sbin/dhclient/options.c | |
parent | e4dff2ea1ff39b620b7919177004a1bd3ce9b216 (diff) |
Unrevert last reversion. otto@ pointed out that it wasn't asprintf()
causing a problem, it was accessing uninitialized pointers.
Diffstat (limited to 'sbin/dhclient/options.c')
-rw-r--r-- | sbin/dhclient/options.c | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/sbin/dhclient/options.c b/sbin/dhclient/options.c index 9447dd3eb78..fd2a1e99833 100644 --- a/sbin/dhclient/options.c +++ b/sbin/dhclient/options.c @@ -1,4 +1,4 @@ -/* $OpenBSD: options.c,v 1.49 2013/01/16 11:02:10 krw Exp $ */ +/* $OpenBSD: options.c,v 1.50 2013/01/16 21:35:41 krw Exp $ */ /* DHCP options parsing and reassembly. */ @@ -463,9 +463,9 @@ do_packet(int len, unsigned int from_port, struct in_addr from, struct dhcp_packet *packet = &client->packet; struct option_data options[256]; struct reject_elem *ap; - void (*handler)(struct in_addr, struct option_data *); - char *type; - int i, options_valid = 1; + void (*handler)(struct in_addr, struct option_data *, char *); + char *type, *info; + int i, rslt, options_valid = 1; if (packet->hlen > sizeof(packet->chaddr)) { note("Discarding packet with invalid hlen."); @@ -503,7 +503,7 @@ do_packet(int len, unsigned int from_port, struct in_addr from, } } - type = ""; + type = "<unknown>"; handler = NULL; if (options[DHO_DHCP_MESSAGE_TYPE].data) { @@ -529,23 +529,31 @@ do_packet(int len, unsigned int from_port, struct in_addr from, type = "BOOTREPLY"; } - if (handler && client->xid == client->packet.xid) { - if (hfrom->hlen == 6) - note("%s from %s (%s)", type, inet_ntoa(from), - ether_ntoa((struct ether_addr *)hfrom->haddr)); - else - note("%s from %s", type, inet_ntoa(from)); - } else + if (hfrom->hlen == 6) + rslt = asprintf(&info, "%s from %s (%s)", type, inet_ntoa(from), + ether_ntoa((struct ether_addr *)hfrom->haddr)); + else + rslt = asprintf(&info, "%s from %s", type, inet_ntoa(from)); + if (rslt == -1) + error("no memory for info string"); + + if (client->xid != client->packet.xid) { +#ifdef DEBUG + debug("XID mismatch on %s", info); +#endif handler = NULL; + } for (ap = config->reject_list; ap && handler; ap = ap->next) if (from.s_addr == ap->addr.s_addr) { - note("%s from %s rejected.", type, inet_ntoa(from)); + note("Rejected %s.", info); handler = NULL; } if (handler) - (*handler)(from, options); + (*handler)(from, options, info); + + free(info); for (i = 0; i < 256; i++) if (options[i].len && options[i].data) |