| author | Manuel Coutand | 2012-04-17 13:24:48 (EDT) |
|---|---|---|
| committer | Eugene Tarassov | 2012-04-18 00:05:25 (EDT) |
| commit | 98d30bafabf6139f26d5634ad613309e3bec1803 (patch) (side-by-side diff) | |
| tree | d0202f209c59bde3d6b4b17de960cdfb5f3499fb | |
| parent | 526dce3f905779014a10d847f02e2372517d46bb (diff) | |
| download | org.eclipse.tcf.agent-98d30bafabf6139f26d5634ad613309e3bec1803.zip org.eclipse.tcf.agent-98d30bafabf6139f26d5634ad613309e3bec1803.tar.gz org.eclipse.tcf.agent-98d30bafabf6139f26d5634ad613309e3bec1803.tar.bz2 | |
Improve Context Query parsing.
| -rw-r--r-- | agent/tcf/services/contextquery.c | 50 |
1 files changed, 40 insertions, 10 deletions
diff --git a/agent/tcf/services/contextquery.c b/agent/tcf/services/contextquery.c index 9e01844..a3cc2a2 100644 --- a/agent/tcf/services/contextquery.c +++ b/agent/tcf/services/contextquery.c @@ -94,19 +94,34 @@ int parse_context_query(const char * q) { } } else if (*q != '"') { - while (*q) { - if ((*q != '_') && - (((*q < '0') || (*q > '9')) && - ((*q < 'a') || (*q > 'z')) && - ((*q < 'A') || (*q > 'Z')))) { - set_errno(ERR_OTHER, "Invalid context query syntax: unquoted strings must only contain alphanumerical characters or '_'"); - return -1; + if ((*q >= '0') && (*q <= '9')) { + while (*q) { + if ((*q < '0') || (*q > '9')) { + set_errno(ERR_OTHER, "Invalid context query syntax: symbols must begin by a letter: a-z, A-Z or _"); + return -1; + } + + add_char(*q++); + + if ((*q == '/') || (*q == '=') || (*q == ',')) { + break; + } } + } else { + while (*q) { + if ((*q != '_') && + (((*q < '0') || (*q > '9')) && + ((*q < 'a') || (*q > 'z')) && + ((*q < 'A') || (*q > 'Z')))) { + set_errno(ERR_OTHER, "Invalid context query syntax: unquoted strings must only contain alphanumerical characters or '_'"); + return -1; + } - add_char(*q++); + add_char(*q++); - if ((*q == '/') || (*q == '=') || (*q == ',')) { - break; + if ((*q == '/') || (*q == '=') || (*q == ',')) { + break; + } } } } @@ -142,12 +157,27 @@ int parse_context_query(const char * q) { else { attr->value = tmp_strdup(str_buf); if (*q != 0) q++; + else { + if (*(q-1) == '=') { + set_errno(ERR_OTHER, "Invalid context query syntax: missing value"); + return -1; + } + if (*(q-1) == ',') { + set_errno(ERR_OTHER, "Invalid context query syntax: missing property"); + return -1; + } + } break; } } attr->parent = attrs; attrs = attr; } + if (*(q-1) == '/') { + set_errno(ERR_OTHER, "Invalid context query syntax: missing context name, property or wildcard"); + return -1; + } + return 0; } |

