-/* $OpenBSD: conflex.c,v 1.35 2017/02/12 13:15:50 krw Exp $ */
+/* $OpenBSD: conflex.c,v 1.36 2017/04/03 18:23:36 krw Exp $ */
/* Lexical scanner for dhclient config file. */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <vis.h>
#include "dhcp.h"
#include "dhcpd.h"
static int ugflag;
static char *tval;
static char tokbuf[1500];
-static char visbuf[1500];
static int get_char(FILE *);
static int get_token(FILE *);
int i, c, bs;
/*
- * Read in characters until an un-escaped '"' is encountered. And
- * then unvis the data that was read.
+ * Read in characters until an un-escaped '"' is encountered.
*/
bs = i = 0;
- memset(visbuf, 0, sizeof(visbuf));
while ((c = get_char(cfile)) != EOF) {
if (c == '"' && bs == 0)
break;
- visbuf[i++] = c;
+ tokbuf[i++] = c;
if (bs)
bs = 0;
else if (c == '\\')
bs = 1;
- if (i == sizeof(visbuf) - 1)
+ if (i == sizeof(tokbuf) - 1)
break;
}
if (bs == 1)
- visbuf[--i] = '\0';
- i = strnunvis(tokbuf, visbuf, sizeof(tokbuf));
+ i--;
if (c == EOF)
parse_warn("eof in string constant");
- else if (i == -1 || i >= sizeof(tokbuf))
+ else if (c != '"')
parse_warn("string constant too long");
+ tokbuf[i] = '\0';
tval = tokbuf;
return (TOK_STRING);
-/* $OpenBSD: parse.c,v 1.46 2017/04/03 15:34:46 krw Exp $ */
+/* $OpenBSD: parse.c,v 1.47 2017/04/03 18:23:36 krw Exp $ */
/* Common parser code for dhcpd and dhclient. */
#include <string.h>
#include <syslog.h>
#include <unistd.h>
+#include <vis.h>
#include "dhcp.h"
#include "dhcpd.h"
char *
parse_string(FILE *cfile)
{
+ static char unvisbuf[1500];
char *val, *s;
- int token;
+ int i, token;
token = next_token(&val, cfile);
if (token != TOK_STRING) {
skip_to_semi(cfile);
return (NULL);
}
- s = strdup(val);
+
+ i = strnunvis(unvisbuf, val, sizeof(unvisbuf));
+ if (i == -1) {
+ parse_warn("could not unvis string");
+ return (NULL);
+ }
+ s = malloc(i+1);
if (!s)
fatalx("no memory for string %s.", val);
+ memcpy(s, unvisbuf, i+1); /* copy terminating NUL */
return (s);
}