-/* $OpenBSD: clparse.c,v 1.107 2017/04/03 15:34:46 krw Exp $ */
+/* $OpenBSD: clparse.c,v 1.108 2017/04/03 19:59:39 krw Exp $ */
/* Parser for dhclient config and lease files. */
parse_reject_statement(cfile);
break;
case TOK_FILENAME:
- string = parse_string(cfile);
+ string = parse_string(cfile, NULL);
free(config->filename);
config->filename = string;
parse_semi(cfile);
break;
case TOK_SERVER_NAME:
- string = parse_string(cfile);
+ string = parse_string(cfile, NULL);
free(config->server_name);
config->server_name = string;
parse_semi(cfile);
struct interface_info *ifi)
{
char *val;
- int token;
+ int len, token;
token = next_token(&val, cfile);
skip_to_semi(cfile);
return;
case TOK_FILENAME:
- lease->filename = parse_string(cfile);
+ lease->filename = parse_string(cfile, NULL);
break;
case TOK_SERVER_NAME:
- lease->server_name = parse_string(cfile);
+ lease->server_name = parse_string(cfile, NULL);
break;
case TOK_SSID:
- val = parse_string(cfile);
- if (val)
- strlcpy(lease->ssid, val, sizeof(lease->ssid));
+ val = parse_string(cfile, &len);
+ if (val && len <= sizeof(lease->ssid)) {
+ memset(lease->ssid, 0, sizeof(lease->ssid));
+ memcpy(lease->ssid, val, len);
+ }
free(val);
break;
case TOK_RENEW:
hunkix += len;
break;
case 't': /* Text string. */
- val = parse_string(cfile);
+ val = parse_string(cfile, &len);
if (val == NULL)
return (-1);
- len = strlen(val);
if (hunkix + len + 1 > sizeof(hunkbuf)) {
parse_warn("option data buffer "
"overflow");
-/* $OpenBSD: dhcpd.h,v 1.161 2017/03/08 20:33:20 krw Exp $ */
+/* $OpenBSD: dhcpd.h,v 1.162 2017/04/03 19:59:39 krw Exp $ */
/*
* Copyright (c) 2004 Henning Brauer <henning@openbsd.org>
extern int warnings_occurred;
void skip_to_semi(FILE *);
int parse_semi(FILE *);
-char *parse_string(FILE *);
+char *parse_string(FILE *, int *);
int parse_ip_addr(FILE *, struct in_addr *);
int parse_cidr(FILE *, unsigned char *);
void parse_ethernet(FILE *, struct ether_addr *);
-/* $OpenBSD: parse.c,v 1.47 2017/04/03 18:23:36 krw Exp $ */
+/* $OpenBSD: parse.c,v 1.48 2017/04/03 19:59:39 krw Exp $ */
/* Common parser code for dhcpd and dhclient. */
}
char *
-parse_string(FILE *cfile)
+parse_string(FILE *cfile, int *len)
{
static char unvisbuf[1500];
char *val, *s;
if (!s)
fatalx("no memory for string %s.", val);
memcpy(s, unvisbuf, i+1); /* copy terminating NUL */
+ if (len != NULL)
+ *len = i;
return (s);
}