Here's a different approach to my previous patch.
Maybe the minus handling should be removed, though, as it didn't seem to be
handled correctly in the previous read_number().
Thanks,
// jacob
Index: usr.sbin/dhcpd/conflex.c
===================================================================
RCS file: /cvs/src/usr.sbin/dhcpd/conflex.c,v
retrieving revision 1.12
diff -u -p -r1.12 conflex.c
--- usr.sbin/dhcpd/conflex.c 5 Dec 2013 22:31:35 -0000 1.12
+++ usr.sbin/dhcpd/conflex.c 7 Jul 2014 07:08:51 -0000
@@ -68,7 +68,6 @@ static int get_char(FILE *);
static int get_token(FILE *);
static void skip_to_eol(FILE *);
static int read_string(FILE *);
-static int read_number(int, FILE *);
static int read_num_or_name(int, FILE *);
static int intern(char *, int);
@@ -137,12 +136,7 @@ get_token(FILE *cfile)
ttok = read_string(cfile);
break;
}
- if ((isascii(c) && isdigit(c)) || c == '-') {
- lexline = l;
- lexchar = p;
- ttok = read_number(c, cfile);
- break;
- } else if (isascii(c) && isalpha(c)) {
+ if ((isascii(c) && isalnum(c)) || c == '-') {
lexline = l;
lexchar = p;
ttok = read_num_or_name(c, cfile);
@@ -250,37 +244,12 @@ read_string(FILE *cfile)
}
static int
-read_number(int c, FILE *cfile)
-{
- int seenx = 0, i = 0, token = TOK_NUMBER;
-
- tokbuf[i++] = c;
- for (; i < sizeof(tokbuf); i++) {
- c = get_char(cfile);
- if (!seenx && c == 'x')
- seenx = 1;
- else if (!isascii(c) || !isxdigit(c)) {
- ungetc(c, cfile);
- ugflag = 1;
- break;
- }
- tokbuf[i] = c;
- }
- if (i == sizeof(tokbuf)) {
- parse_warn("numeric token larger than internal buffer");
- i--;
- }
- tokbuf[i] = 0;
- tval = tokbuf;
-
- return (token);
-}
-
-static int
read_num_or_name(int c, FILE *cfile)
{
int i = 0;
- int rv = TOK_NUMBER_OR_NAME;
+ int rv = TOK_NUMBER;
+ int seenx = 0;
+ int seenminus = 0;
tokbuf[i++] = c;
for (; i < sizeof(tokbuf); i++) {
@@ -290,8 +259,21 @@ read_num_or_name(int c, FILE *cfile)
ugflag = 1;
break;
}
- if (!isxdigit(c))
- rv = TOK_NAME;
+ switch (rv) {
+ case TOK_NUMBER:
+ if (!seenminus && c == '-') {
+ seenminus = 1;
+ break;
+ } else if (!isdigit(c))
+ rv = TOK_NUMBER_OR_NAME;
+ /* FALLTHROUGH */
+ case TOK_NUMBER_OR_NAME:
+ if (!seenx && c == 'x') {
+ seenx = 1;
+ break;
+ } else if (!isxdigit(c))
+ rv = TOK_NAME;
+ }
tokbuf[i] = c;
}
if (i == sizeof(tokbuf)) {