summaryrefslogtreecommitdiff
path: root/src/lib/eet/eet_data.c
diff options
context:
space:
mode:
authorGustavo Sverzut Barbieri <gustavo.barbieri@intel.com>2014-03-13 22:00:27 -0300
committerGustavo Sverzut Barbieri <gustavo.barbieri@intel.com>2014-03-13 22:08:44 -0300
commitf2a1f14abd51946c75b96730a989ec334194ed76 (patch)
treec554132bd76c4e5c67eb8e3cf71edcb502994ea7 /src/lib/eet/eet_data.c
parent6242271e74eca2b483f603b72e170e049e07aa18 (diff)
eet: fix tokenizer's escape logic.
Tokenizer's approach of looking back is horrible and breaks the following simple case (bug I had that lead to this patch): "string\\" As the parser would get the end quote and check the previous character if it was a backslash and it was, but it was not escaping the quote, but being escaped by the previous backslash. The best approach is to first check for escape and then go to quote. Escape is simple and only the following byte, so we enter escape, process the byte and then are back to regular mode (be it quote or unquote). Added testcase so we avoid breaking it again. @bugfix cherry-pick
Diffstat (limited to '')
-rw-r--r--src/lib/eet/eet_data.c42
1 files changed, 25 insertions, 17 deletions
diff --git a/src/lib/eet/eet_data.c b/src/lib/eet/eet_data.c
index b687b2e0ff..ea51ed0f4a 100644
--- a/src/lib/eet/eet_data.c
+++ b/src/lib/eet/eet_data.c
@@ -2775,6 +2775,7 @@ _eet_data_dump_token_get(const char *src,
2775 char *tok = NULL; 2775 char *tok = NULL;
2776 int in_token = 0; 2776 int in_token = 0;
2777 int in_quote = 0; 2777 int in_quote = 0;
2778 int in_escape = 0;
2778 int tlen = 0, tsize = 0; 2779 int tlen = 0, tsize = 0;
2779 2780
2780#define TOK_ADD(x) \ 2781#define TOK_ADD(x) \
@@ -2792,25 +2793,32 @@ _eet_data_dump_token_get(const char *src,
2792 { 2793 {
2793 if (in_token) 2794 if (in_token)
2794 { 2795 {
2795 if (in_quote) 2796 if (in_escape)
2796 { 2797 {
2797 if ((p[0] == '\"') && (p > src) && (p[-1] != '\\')) 2798 switch (p[0]) {
2799 case 'n':
2800 TOK_ADD('\n');
2801 break;
2802 case '"':
2803 case '\'':
2804 case '\\':
2805 TOK_ADD(p[0]);
2806 break;
2807 default:
2808 ERR("Unknow escape character %#x (%c). Append as is",
2809 p[0], p[0]);
2810 TOK_ADD(p[0]);
2811 }
2812 in_escape = 0;
2813 }
2814 else if (p[0] == '\\')
2815 {
2816 in_escape = 1;
2817 }
2818 else if (in_quote)
2819 {
2820 if (p[0] == '\"')
2798 in_quote = 0; 2821 in_quote = 0;
2799 else if ((p[0] == '\\') && (*len > 1) &&
2800 (p[1] == '\"'))
2801 {
2802/* skip */
2803 }
2804 else if ((p[0] == '\\') && (p > src) && (p[-1] == '\\'))
2805 {
2806/* skip */
2807 }
2808 else if ((p[0] == '\\') && (*len > 1) && (p[1] == 'n'))
2809 {
2810/* skip */
2811 }
2812 else if ((p[0] == 'n') && (p > src) && (p[-1] == '\\'))
2813 TOK_ADD('\n');
2814 else 2822 else
2815 TOK_ADD(p[0]); 2823 TOK_ADD(p[0]);
2816 } 2824 }