case S_STRING:
if (*p++ != '"')
break;
- for (p2 = p; (p2 = strpbrk(p2, "\"\\")); p2++) {
- if (*p2 == '"') {
- *p2 = 0;
- break;
- }
- memmove(p2, p2 + 1, strlen(p2));
- }
- if (!p2) {
+ /* Last char has to be a '"' */
+ if (p[strlen(p) - 1] != '"') {
if (def != S_DEF_AUTO)
conf_warning("invalid string found");
return 1;
}
+ /* Overwrite '"' with \0 for string termination */
+ p[strlen(p) - 1] = 0;
/* fall through */
case S_INT:
case S_HEX:
struct conf_printer *printer, void *printer_arg)
{
const char *str;
+ char *str2;
switch (sym->type) {
case S_OTHER:
break;
case S_STRING:
str = sym_get_string_value(sym);
- str = sym_escape_string_value(str);
- printer->print_symbol(fp, sym, str, printer_arg);
- free((void *)str);
+ str2 = xmalloc(strlen(str) + 3);
+ sprintf(str2, "\"%s\"", str);
+ printer->print_symbol(fp, sym, str2, printer_arg);
+ free((void *)str2);
break;
default:
str = sym_get_string_value(sym);
return res;
}
-const char *sym_escape_string_value(const char *in)
-{
- const char *p;
- size_t reslen;
- char *res;
- size_t l;
-
- reslen = strlen(in) + strlen("\"\"") + 1;
-
- p = in;
- for (;;) {
- l = strcspn(p, "\"\\");
- p += l;
-
- if (p[0] == '\0')
- break;
-
- reslen++;
- p++;
- }
-
- res = xmalloc(reslen);
- res[0] = '\0';
-
- strcat(res, "\"");
-
- p = in;
- for (;;) {
- l = strcspn(p, "\"\\");
- strncat(res, p, l);
- p += l;
-
- if (p[0] == '\0')
- break;
-
- strcat(res, "\\");
- strncat(res, p++, 1);
- }
-
- strcat(res, "\"");
- return res;
-}
-
struct sym_match {
struct symbol *sym;
off_t so, eo;