Changeset View
Changeset View
Standalone View
Standalone View
head/sbin/dhclient/parse.c
Show First 20 Lines • Show All 125 Lines • ▼ Show 20 Lines | if (token != STRING) { | ||||
return (NULL); | return (NULL); | ||||
} | } | ||||
valsize = strlen(val) + 1; | valsize = strlen(val) + 1; | ||||
s = malloc(valsize); | s = malloc(valsize); | ||||
if (!s) | if (!s) | ||||
error("no memory for string %s.", val); | error("no memory for string %s.", val); | ||||
memcpy(s, val, valsize); | memcpy(s, val, valsize); | ||||
if (!parse_semi(cfile)) | if (!parse_semi(cfile)) { | ||||
free(s); | |||||
return (NULL); | return (NULL); | ||||
} | |||||
return (s); | return (s); | ||||
} | } | ||||
int | int | ||||
parse_ip_addr(FILE *cfile, struct iaddr *addr) | parse_ip_addr(FILE *cfile, struct iaddr *addr) | ||||
{ | { | ||||
addr->len = 4; | addr->len = 4; | ||||
if (parse_numeric_aggregate(cfile, addr->iabuf, | if (parse_numeric_aggregate(cfile, addr->iabuf, | ||||
▲ Show 20 Lines • Show All 97 Lines • ▼ Show 20 Lines | |||||
parse_numeric_aggregate(FILE *cfile, unsigned char *buf, int *max, | parse_numeric_aggregate(FILE *cfile, unsigned char *buf, int *max, | ||||
int separator, int base, int size) | int separator, int base, int size) | ||||
{ | { | ||||
unsigned char *bufp = buf, *s = NULL; | unsigned char *bufp = buf, *s = NULL; | ||||
int token, count = 0; | int token, count = 0; | ||||
char *val, *t; | char *val, *t; | ||||
size_t valsize; | size_t valsize; | ||||
pair c = NULL; | pair c = NULL; | ||||
unsigned char *lbufp = NULL; | |||||
if (!bufp && *max) { | if (!bufp && *max) { | ||||
bufp = malloc(*max * size / 8); | lbufp = bufp = malloc(*max * size / 8); | ||||
if (!bufp) | if (!bufp) | ||||
error("can't allocate space for numeric aggregate"); | error("can't allocate space for numeric aggregate"); | ||||
} else | } else | ||||
s = bufp; | s = bufp; | ||||
do { | do { | ||||
if (count) { | if (count) { | ||||
token = peek_token(&val, cfile); | token = peek_token(&val, cfile); | ||||
if (token != separator) { | if (token != separator) { | ||||
if (!*max) | if (!*max) | ||||
break; | break; | ||||
if (token != RBRACE && token != LBRACE) | if (token != RBRACE && token != LBRACE) | ||||
token = next_token(&val, cfile); | token = next_token(&val, cfile); | ||||
parse_warn("too few numbers."); | parse_warn("too few numbers."); | ||||
if (token != SEMI) | if (token != SEMI) | ||||
skip_to_semi(cfile); | skip_to_semi(cfile); | ||||
free(lbufp); | |||||
return (NULL); | return (NULL); | ||||
} | } | ||||
token = next_token(&val, cfile); | token = next_token(&val, cfile); | ||||
} | } | ||||
token = next_token(&val, cfile); | token = next_token(&val, cfile); | ||||
if (token == EOF) { | if (token == EOF) { | ||||
parse_warn("unexpected end of file"); | parse_warn("unexpected end of file"); | ||||
break; | break; | ||||
} | } | ||||
/* Allow NUMBER_OR_NAME if base is 16. */ | /* Allow NUMBER_OR_NAME if base is 16. */ | ||||
if (token != NUMBER && | if (token != NUMBER && | ||||
(base != 16 || token != NUMBER_OR_NAME)) { | (base != 16 || token != NUMBER_OR_NAME)) { | ||||
parse_warn("expecting numeric value."); | parse_warn("expecting numeric value."); | ||||
skip_to_semi(cfile); | skip_to_semi(cfile); | ||||
free(lbufp); | |||||
return (NULL); | return (NULL); | ||||
} | } | ||||
/* | /* | ||||
* If we can, convert the number now; otherwise, build a | * If we can, convert the number now; otherwise, build a | ||||
* linked list of all the numbers. | * linked list of all the numbers. | ||||
*/ | */ | ||||
if (s) { | if (s) { | ||||
convert_num(s, val, base, size); | convert_num(s, val, base, size); | ||||
s += size / 8; | s += size / 8; | ||||
} else { | } else { | ||||
valsize = strlen(val) + 1; | valsize = strlen(val) + 1; | ||||
t = malloc(valsize); | t = malloc(valsize); | ||||
if (!t) | if (!t) | ||||
error("no temp space for number."); | error("no temp space for number."); | ||||
memcpy(t, val, valsize); | memcpy(t, val, valsize); | ||||
c = cons(t, c); | c = cons(t, c); | ||||
} | } | ||||
} while (++count != *max); | } while (++count != *max); | ||||
/* If we had to cons up a list, convert it now. */ | /* If we had to cons up a list, convert it now. */ | ||||
if (c) { | if (c) { | ||||
free(lbufp); | |||||
bufp = malloc(count * size / 8); | bufp = malloc(count * size / 8); | ||||
if (!bufp) | if (!bufp) | ||||
error("can't allocate space for numeric aggregate."); | error("can't allocate space for numeric aggregate."); | ||||
s = bufp + count - size / 8; | s = bufp + count - size / 8; | ||||
*max = count; | *max = count; | ||||
} | } | ||||
while (c) { | while (c) { | ||||
pair cdr = c->cdr; | pair cdr = c->cdr; | ||||
▲ Show 20 Lines • Show All 272 Lines • Show Last 20 Lines |