From a5b0c094220d09a3a4ef30332c181b2522cb02f3 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 6 Dec 2014 18:27:24 +0100 Subject: mds-kbdc: parse_quoted_string are takes care of unquotes strings with escapes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/mds-kbdc/compile-layout.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'src/mds-kbdc') diff --git a/src/mds-kbdc/compile-layout.c b/src/mds-kbdc/compile-layout.c index 647ae41..aa1f4b2 100644 --- a/src/mds-kbdc/compile-layout.c +++ b/src/mds-kbdc/compile-layout.c @@ -281,6 +281,14 @@ static char32_t* parse_quoted_string(mds_kbdc_tree_t* restrict tree, const char* buf[buf_ptr] = '\0', buf_ptr = 0; \ fail_if ((subrc = string_decode(buf), subrc == NULL)); \ COPY +#define CHAR_ERROR(...) \ + do \ + { \ + NEW_ERROR(__VA_ARGS__); \ + error->end = lineoff + (size_t)(raw - raw_); \ + error->start = error->end - 1; \ + } \ + while (0) const char* restrict raw_ = raw; char32_t* restrict subrc = NULL; @@ -290,7 +298,7 @@ static char32_t* parse_quoted_string(mds_kbdc_tree_t* restrict tree, const char* char* restrict old_buf = NULL; size_t rc_ptr = 0, rc_size = 0, n; size_t buf_ptr = 0, buf_size = 0; - int quote = 0, escape = 1; + int quote = 0, escape = 0; char c; int saved_errno; @@ -307,6 +315,8 @@ static char32_t* parse_quoted_string(mds_kbdc_tree_t* restrict tree, const char* { /* Close or open quote, of it got closed, convert the buffered UTF-8 text to UTF-32. */ if (quote ^= 1) continue; + if ((quote == 1) && (raw != raw_ + 1)) + CHAR_ERROR(tree, WARNING, "strings should either be unquoted or unclosed in one large quoted"); STORE; } else if (c == '\\') @@ -318,9 +328,7 @@ static char32_t* parse_quoted_string(mds_kbdc_tree_t* restrict tree, const char* else if ((quote == 0) && (tree->processed != PROCESS_LEVEL)) { /* Only escapes may be used without quotes, if the string contains quotes. */ - NEW_ERROR(tree, ERROR, "only escapes may be outside quotes in quoted strings"); - error->end = lineoff + (size_t)(raw - raw_); - error->start = error->end - 1; + CHAR_ERROR(tree, ERROR, "only escapes may be outside quotes in quoted strings"); tree->processed = PROCESS_LEVEL; } else @@ -359,9 +367,12 @@ static char32_t* parse_quoted_string(mds_kbdc_tree_t* restrict tree, const char* free(subrc); free(old_rc); free(old_buf); + free(rc); free(buf); return errno = saved_errno, NULL; +#undef CHAR_ERROR #undef STORE +#undef COPY #undef GROW_BUF } @@ -394,7 +405,7 @@ static char32_t* parse_unquoted_string(mds_kbdc_tree_t* restrict tree, const cha static char32_t* parse_string(mds_kbdc_tree_t* restrict tree, const char* restrict raw, size_t lineoff) { mds_kbdc_tree_t* old_last_value_statement = last_value_statement; - char32_t* rc = ((*raw == '"') ? parse_quoted_string : parse_unquoted_string)(tree, raw, lineoff); + char32_t* rc = (strchr("\"\\", *raw) ? parse_quoted_string : parse_unquoted_string)(tree, raw, lineoff); last_value_statement = old_last_value_statement; return rc; } -- cgit v1.2.3-70-g09d2