change.
-/* $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 <henning@openbsd.org>
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) {
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:
/*
{
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));
-/* $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 <henning@openbsd.org>
/* 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 *);
-/* $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. */
* 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;
}
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);
}
/*