diff options
-rw-r--r-- | sbin/dhclient/conflex.c | 39 |
1 files changed, 17 insertions, 22 deletions
diff --git a/sbin/dhclient/conflex.c b/sbin/dhclient/conflex.c index d6be36f8c42..02533c4ef83 100644 --- a/sbin/dhclient/conflex.c +++ b/sbin/dhclient/conflex.c @@ -1,4 +1,4 @@ -/* $OpenBSD: conflex.c,v 1.21 2013/06/09 00:30:06 krw Exp $ */ +/* $OpenBSD: conflex.c,v 1.22 2013/06/09 01:51:58 krw Exp $ */ /* Lexical scanner for dhclient config file. */ @@ -233,34 +233,29 @@ skip_to_eol(FILE *cfile) static int read_string(FILE *cfile) { - int i, c, bs = 0; + int i, c, bs; - for (i = 0; i < sizeof(tokbuf); i++) { + bs = i = 0; + do { c = get_char(cfile); - if (c == EOF) { - parse_warn("eof in string constant"); - break; - } - if (bs) { + if (bs) bs = 0; - tokbuf[i] = c; - } else if (c == '\\') + else if (c == '\\') bs = 1; - else if (c == '"') - break; - else - tokbuf[i] = c; - } - /* - * Normally, I'd feel guilty about this, but we're talking about - * strings that'll fit in a DHCP packet here. - */ - if (i == sizeof(tokbuf)) { + + if (c != '"' && c != EOF && bs == 0) + tokbuf[i++] = c; + + } while (i < (sizeof(tokbuf) - 1) && c != EOF && c != '"'); + + if (c == EOF) + parse_warn("eof in string constant"); + else if (c != '"') parse_warn("string constant larger than internal buffer"); - i--; - } + tokbuf[i] = 0; tval = tokbuf; + return (TOK_STRING); } |