-/* $OpenBSD: clparse.c,v 1.119 2017/07/08 20:38:31 krw Exp $ */
+/* $OpenBSD: clparse.c,v 1.120 2017/07/09 18:45:27 krw Exp $ */
/* Parser for dhclient config and lease files. */
if (len == -1)
return (-1);
hunkix += len;
+ dp = NULL;
break;
case 't': /* Text string. */
val = parse_string(cfile, &len);
nul_term = 1;
hunkix += len;
free(val);
+ dp = NULL;
break;
case 'I': /* IP address. */
if (!parse_ip_addr(cfile, &ip_addr))
return (-1);
len = sizeof(ip_addr);
dp = (uint8_t *)&ip_addr;
-alloc:
- if (hunkix + len > sizeof(hunkbuf)) {
- parse_warn("option data buffer "
- "overflow");
- skip_to_semi(cfile);
- return (-1);
- }
- memcpy(&hunkbuf[hunkix], dp, len);
- hunkix += len;
break;
case 'l': /* Signed 32-bit integer. */
- if (!parse_decimal(cfile, buf, *fmt)) {
+ if (!parse_decimal(cfile, buf, 'l')) {
parse_warn("expecting signed 32-bit "
"integer.");
skip_to_semi(cfile);
}
len = 4;
dp = buf;
- goto alloc;
+ break;
case 'L': /* Unsigned 32-bit integer. */
- if (!parse_decimal(cfile, buf, *fmt)) {
+ if (!parse_decimal(cfile, buf, 'L')) {
parse_warn("expecting unsigned 32-bit "
"integer.");
skip_to_semi(cfile);
}
len = 4;
dp = buf;
- goto alloc;
+ break;
case 'S': /* Unsigned 16-bit integer. */
- if (!parse_decimal(cfile, buf, *fmt)) {
+ if (!parse_decimal(cfile, buf, 'S')) {
parse_warn("expecting unsigned 16-bit "
"integer.");
skip_to_semi(cfile);
}
len = 2;
dp = buf;
- goto alloc;
+ break;
case 'B': /* Unsigned 8-bit integer. */
- if (!parse_decimal(cfile, buf, *fmt)) {
+ if (!parse_decimal(cfile, buf, 'B')) {
parse_warn("expecting unsigned 8-bit "
"integer.");
skip_to_semi(cfile);
}
len = 1;
dp = buf;
- goto alloc;
+ break;
case 'f': /* Boolean flag. */
- token = next_token(&val, cfile);
- if (!is_identifier(token)) {
- parse_warn("expecting identifier.");
-bad_flag:
- if (token != ';')
- skip_to_semi(cfile);
- return (-1);
- }
- if (!strcasecmp(val, "true") ||
- !strcasecmp(val, "on"))
- buf[0] = 1;
- else if (!strcasecmp(val, "false") ||
- !strcasecmp(val, "off"))
- buf[0] = 0;
- else {
+ if (!parse_boolean(cfile, buf)) {
parse_warn("expecting boolean.");
- goto bad_flag;
+ skip_to_semi(cfile);
+ return (-1);
}
len = 1;
dp = buf;
- goto alloc;
+ break;
case 'C':
if (!parse_cidr(cfile, cidr))
return (-1);
len = 1 + (cidr[0] + 7) / 8;
dp = cidr;
- goto alloc;
+ break;
default:
log_warnx("Bad format %c in "
"parse_option_param.", *fmt);
skip_to_semi(cfile);
return (-1);
}
+ if (dp != NULL && len > 0) {
+ if (hunkix + len > sizeof(hunkbuf)) {
+ parse_warn("option data buffer "
+ "overflow");
+ skip_to_semi(cfile);
+ return (-1);
+ }
+ memcpy(&hunkbuf[hunkix], dp, len);
+ hunkix += len;
+ }
}
token = peek_token(NULL, cfile);
if (*fmt == 'A' && token == ',')
-/* $OpenBSD: parse.c,v 1.55 2017/07/08 00:36:10 krw Exp $ */
+/* $OpenBSD: parse.c,v 1.56 2017/07/09 18:45:27 krw Exp $ */
/* Common parser code for dhcpd and dhclient. */
parse_semi(cfile);
}
+int
+parse_boolean(FILE *cfile, unsigned char *buf)
+{
+ char *val;
+ int token;
+
+ token = next_token(&val, cfile);
+ if (is_identifier(token)) {
+ if (strcasecmp(val, "true") == 0 ||
+ strcasecmp(val, "on") == 0) {
+ buf[0] = 1;
+ return (1);
+ }
+ if (strcasecmp(val, "false") == 0 ||
+ strcasecmp(val, "off") == 0) {
+ buf[0] = 0;
+ return (1);
+ }
+ }
+
+ return (0);
+}
+
int
parse_decimal(FILE *cfile, unsigned char *buf, char fmt)
{