-/* $OpenBSD: clparse.c,v 1.120 2017/07/09 18:45:27 krw Exp $ */
+/* $OpenBSD: clparse.c,v 1.121 2017/07/09 21:29:19 krw Exp $ */
/* Parser for dhclient config and lease files. */
if (++len == max)
break;
if (peek_token(NULL, cfile) == ';')
- return (len);
+ return len;
}
if (token != ':') {
parse_warn("expecting ':'.");
skip_to_semi(cfile);
- return (-1);
+ return -1;
} else {
parse_warn("expecting hex value.");
skip_to_semi(cfile);
- return (-1);
+ return -1;
}
} else if (token == TOK_STRING) {
token = next_token(&val, cfile);
if (len + 1 > max) {
parse_warn("string constant too long.");
skip_to_semi(cfile);
- return (-1);
+ return -1;
}
memcpy(buf, val, len + 1);
} else {
parse_warn("expecting string or hex data.");
if (token != ';')
skip_to_semi(cfile);
- return (-1);
+ return -1;
}
- return (len);
+ return len;
}
/*
token = next_token(&val, cfile);
if (token == ';' && ix == 0) {
/* Empty list. */
- return (0);
+ return 0;
}
if (!is_identifier(token)) {
parse_warn("expecting option name.");
} while (token == ',');
if (parse_semi(cfile))
- return (ix);
+ return ix;
syntaxerror:
if (token != ';')
skip_to_semi(cfile);
- return (-1);
+ return -1;
}
/*
parse_warn("expecting identifier.");
if (token != ';')
skip_to_semi(cfile);
- return (-1);
+ return -1;
}
/* Look up the actual option info. */
if (code == DHO_END) {
parse_warn("unknown option name.");
skip_to_semi(cfile);
- return (-1);
+ return -1;
}
/* Parse the option data. */
len = parse_X(cfile, &hunkbuf[hunkix],
sizeof(hunkbuf) - hunkix);
if (len == -1)
- return (-1);
+ return -1;
hunkix += len;
dp = NULL;
break;
case 't': /* Text string. */
val = parse_string(cfile, &len);
if (val == NULL)
- return (-1);
+ return -1;
if (hunkix + len + 1 > sizeof(hunkbuf)) {
parse_warn("option data buffer "
"overflow");
skip_to_semi(cfile);
- return (-1);
+ return -1;
}
memcpy(&hunkbuf[hunkix], val, len + 1);
nul_term = 1;
break;
case 'I': /* IP address. */
if (!parse_ip_addr(cfile, &ip_addr))
- return (-1);
+ return -1;
len = sizeof(ip_addr);
dp = (uint8_t *)&ip_addr;
break;
parse_warn("expecting signed 32-bit "
"integer.");
skip_to_semi(cfile);
- return (-1);
+ return -1;
}
len = 4;
dp = buf;
parse_warn("expecting unsigned 32-bit "
"integer.");
skip_to_semi(cfile);
- return (-1);
+ return -1;
}
len = 4;
dp = buf;
parse_warn("expecting unsigned 16-bit "
"integer.");
skip_to_semi(cfile);
- return (-1);
+ return -1;
}
len = 2;
dp = buf;
parse_warn("expecting unsigned 8-bit "
"integer.");
skip_to_semi(cfile);
- return (-1);
+ return -1;
}
len = 1;
dp = buf;
if (!parse_boolean(cfile, buf)) {
parse_warn("expecting boolean.");
skip_to_semi(cfile);
- return (-1);
+ return -1;
}
len = 1;
dp = buf;
break;
case 'C':
if (!parse_cidr(cfile, cidr))
- return (-1);
+ return -1;
len = 1 + (cidr[0] + 7) / 8;
dp = cidr;
break;
log_warnx("Bad format %c in "
"parse_option_param.", *fmt);
skip_to_semi(cfile);
- return (-1);
+ return -1;
}
if (dp != NULL && len > 0) {
if (hunkix + len > sizeof(hunkbuf)) {
parse_warn("option data buffer "
"overflow");
skip_to_semi(cfile);
- return (-1);
+ return -1;
}
memcpy(&hunkbuf[hunkix], dp, len);
hunkix += len;
} while (*fmt == 'A' && token == ',');
if (!parse_semi(cfile))
- return (-1);
+ return -1;
options[code].data = malloc(hunkix + nul_term);
if (!options[code].data)
fatalx("out of memory allocating option data.");
memcpy(options[code].data, hunkbuf, hunkix + nul_term);
options[code].len = hunkix;
- return (code);
+ return code;
}
void