From: krw Date: Fri, 7 Apr 2017 15:03:00 +0000 (+0000) Subject: Simply decoding of domain search option. No intentional functional X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=4d36d16af2079dac16b931c2a8fbe46a423cbb60;p=openbsd Simply decoding of domain search option. No intentional functional change. --- diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c index 13f346750c8..d3579f79e57 100644 --- a/sbin/dhclient/dhclient.c +++ b/sbin/dhclient/dhclient.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dhclient.c,v 1.407 2017/04/04 15:15:48 krw Exp $ */ +/* $OpenBSD: dhclient.c,v 1.408 2017/04/07 15:03:00 krw Exp $ */ /* * Copyright 2004 Henning Brauer @@ -1266,7 +1266,7 @@ packet_to_lease(struct interface_info *ifi, struct in_addr client_addr, char ifname[IF_NAMESIZE]; struct client_lease *lease; char *pretty, *buf; - int i, sz; + int i; lease = calloc(1, sizeof(struct client_lease)); if (!lease) { @@ -1289,18 +1289,13 @@ packet_to_lease(struct interface_info *ifi, struct in_addr client_addr, switch (i) { case DHO_DOMAIN_SEARCH: /* Must decode the option into text to check names. */ - buf = calloc(1, DHCP_DOMAIN_SEARCH_LEN); + buf = pretty_print_domain_search(options[i].data, + options[i].len); if (buf == NULL) - fatalx("No memory to decode domain search"); - sz = pretty_print_domain_search(buf, - DHCP_DOMAIN_SEARCH_LEN, - options[i].data, options[i].len); - if (strlen(buf) == 0) continue; - if (sz == -1 || !res_hnok_list(buf)) + if (!res_hnok_list(buf)) log_warnx("Bogus data for option %s", dhcp_options[i].name); - free(buf); break; case DHO_DOMAIN_NAME: /* @@ -2707,24 +2702,20 @@ resolv_conf_contents(struct interface_info *ifi, { char *dn, *ns, *nss[MAXNS], *contents, *courtesy, *p, *buf; size_t len; - int i, rslt, sz; + int i, rslt; memset(nss, 0, sizeof(nss)); if (domainsearch->len) { - buf = calloc(1, DHCP_DOMAIN_SEARCH_LEN); + buf = pretty_print_domain_search(domainsearch->data, + domainsearch->len); if (buf == NULL) - fatalx("No memory to decode domain search"); - sz = pretty_print_domain_search(buf, DHCP_DOMAIN_SEARCH_LEN, - domainsearch->data, domainsearch->len); - if (sz == -1) dn = strdup(""); else { rslt = asprintf(&dn, "search %s\n", buf); if (rslt == -1) dn = NULL; } - free(buf); } else if (domainname->len) { rslt = asprintf(&dn, "search %s\n", pretty_print_option(DHO_DOMAIN_NAME, domainname, 0)); diff --git a/sbin/dhclient/dhcpd.h b/sbin/dhclient/dhcpd.h index 9b98f9b36cf..8eaac8486e6 100644 --- a/sbin/dhclient/dhcpd.h +++ b/sbin/dhclient/dhcpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dhcpd.h,v 1.165 2017/04/05 18:22:30 krw Exp $ */ +/* $OpenBSD: dhcpd.h,v 1.166 2017/04/07 15:03:00 krw Exp $ */ /* * Copyright (c) 2004 Henning Brauer @@ -187,11 +187,10 @@ extern struct in_addr active_addr; /* options.c */ int cons_options(struct interface_info *, struct option_data *); char *pretty_print_option(unsigned int, struct option_data *, int); +char *pretty_print_domain_search(unsigned char *, size_t); int pretty_print_string(unsigned char *, size_t, unsigned char *, size_t, int); int pretty_print_classless_routes(unsigned char *, size_t, unsigned char *, size_t); -int pretty_print_domain_search(unsigned char *, size_t, unsigned char *, - size_t); void do_packet(struct interface_info *, unsigned int, struct in_addr, struct ether_addr *); diff --git a/sbin/dhclient/options.c b/sbin/dhclient/options.c index a339681e541..aad23855283 100644 --- a/sbin/dhclient/options.c +++ b/sbin/dhclient/options.c @@ -1,4 +1,4 @@ -/* $OpenBSD: options.c,v 1.83 2017/03/26 21:33:36 krw Exp $ */ +/* $OpenBSD: options.c,v 1.84 2017/04/07 15:03:01 krw Exp $ */ /* DHCP options parsing and reassembly. */ @@ -389,16 +389,14 @@ expand_search_domain_name(unsigned char *src, size_t srclen, int *offset, * Must special case DHO_DOMAIN_SEARCH because it is encoded as described * in RFC 1035 section 4.1.4. */ -int -pretty_print_domain_search(unsigned char *dst, size_t dstlen, - unsigned char *src, size_t srclen) +char * +pretty_print_domain_search(unsigned char *src, size_t srclen) { + static char domain_search[DHCP_DOMAIN_SEARCH_LEN]; int offset, len, expanded_len, domains; - unsigned char *domain_search, *cursor; + unsigned char *cursor; - domain_search = calloc(1, DHCP_DOMAIN_SEARCH_LEN); - if (domain_search == NULL) - fatalx("Can't allocate storage for expanded domain-search\n"); + memset(domain_search, 0, sizeof(domain_search)); /* Compute expanded length. */ expanded_len = len = 0; @@ -412,22 +410,15 @@ pretty_print_domain_search(unsigned char *dst, size_t dstlen, } len = expand_search_domain_name(src, srclen, &offset, domain_search); - if (len == -1) { - free(domain_search); - return (-1); - } + if (len == -1) + return (NULL); domains++; expanded_len += len; - if (domains > DHCP_DOMAIN_SEARCH_CNT) { - free(domain_search); - return (-1); - } + if (domains > DHCP_DOMAIN_SEARCH_CNT) + return (NULL); } - strlcat(dst, domain_search, dstlen); - free(domain_search); - - return (0); + return (domain_search); } /*