Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEugene Tarassov2013-05-17 18:05:38 -0400
committerEugene Tarassov2013-05-17 18:05:38 -0400
commit82093b818414ffc335b9ad95b846cde80b08b064 (patch)
treef0ecce8622f26b652bacfb63f0690fe1a9539379
parentba19261cb0d67cf5b2287fe1b1cd5d755a795d72 (diff)
downloadorg.eclipse.tcf.agent-82093b818414ffc335b9ad95b846cde80b08b064.tar.gz
org.eclipse.tcf.agent-82093b818414ffc335b9ad95b846cde80b08b064.tar.xz
org.eclipse.tcf.agent-82093b818414ffc335b9ad95b846cde80b08b064.zip
TCF Agent: fixed few issues with space characters in command arguments
-rw-r--r--agent/tcf/framework/json.c41
-rw-r--r--agent/tcf/framework/json.h3
-rw-r--r--agent/tcf/framework/protocol.c4
-rw-r--r--agent/tcf/services/discovery.c2
-rw-r--r--agent/tcf/services/symbols.c2
-rw-r--r--agent/tcf/services/symbols_proxy.c2
6 files changed, 32 insertions, 22 deletions
diff --git a/agent/tcf/framework/json.c b/agent/tcf/framework/json.c
index 80ab8fb2..6f80a6f1 100644
--- a/agent/tcf/framework/json.c
+++ b/agent/tcf/framework/json.c
@@ -45,8 +45,10 @@
#define ENCODING_BINARY 0
#define ENCODING_BASE64 1
-#define ignore_whitespace(ch, inp) do { while (isspace(ch)) (ch) = read_stream(inp); } while (0)
-#define read_whitespace(inp) do { while (isspace(peek_stream(inp))) read_stream(inp); } while (0)
+#define ignore_whitespace(ch, inp) do { while (ch > 0 && isspace(ch)) (ch) = read_stream(inp); } while (0)
+
+#define read_whitespace(inp) do { int ch = peek_stream(inp); \
+ while (ch > 0 && isspace(ch)) { read_stream(inp); ch = peek_stream(inp); } } while (0)
static char * buf = NULL;
static size_t buf_pos = 0;
@@ -448,8 +450,7 @@ int json_read_struct(InputStream * inp, JsonStructCallBack * call_back, void * a
exception(ERR_PROTOCOL);
return 1;
}
- read_whitespace(inp);
- if (peek_stream(inp) == '}') {
+ if (json_peek(inp) == '}') {
read_stream(inp);
return 1;
}
@@ -494,8 +495,7 @@ char ** json_read_alloc_string_array(InputStream * inp, int * cnt) {
buf_pos = 0;
- read_whitespace(inp);
- if (peek_stream(inp) == ']') {
+ if (json_peek(inp) == ']') {
read_stream(inp);
}
else {
@@ -575,8 +575,7 @@ int json_read_array(InputStream * inp, JsonArrayCallBack * call_back, void * arg
exception(ERR_PROTOCOL);
return 1;
}
- read_whitespace(inp);
- if (peek_stream(inp) == ']') {
+ if (json_peek(inp) == ']') {
read_stream(inp);
return 1;
}
@@ -669,9 +668,8 @@ void json_read_binary_end(JsonReadBinaryState * state) {
char * json_read_alloc_binary(InputStream * inp, size_t * size) {
char * data = NULL;
- int ch = peek_stream(inp);
*size = 0;
- if (ch == 'n') {
+ if (json_peek(inp) == 'n') {
read_stream(inp);
json_test_char(inp, 'u');
json_test_char(inp, 'l');
@@ -859,8 +857,7 @@ static void skip_object(InputStream * inp) {
return;
}
if (ch == '[') {
- read_whitespace(inp);
- if (peek_stream(inp) == ']') {
+ if (json_peek(inp) == ']') {
skip_char(inp);
}
else {
@@ -877,8 +874,7 @@ static void skip_object(InputStream * inp) {
return;
}
if (ch == '{') {
- read_whitespace(inp);
- if (peek_stream(inp) == '}') {
+ if (json_peek(inp) == '}') {
skip_char(inp);
}
else {
@@ -926,8 +922,19 @@ void json_skip_object(InputStream * inp) {
skip_object(inp);
}
-void json_test_char(InputStream * inp, int ch) {
- check_char(read_stream(inp), ch);
+void json_test_char(InputStream * inp, int x) {
+ int ch = read_stream(inp);
+ if (x != MARKER_EOM) ignore_whitespace(ch, inp);
+ check_char(ch, x);
+}
+
+int json_peek(InputStream * inp) {
+ int ch = peek_stream(inp);
+ while (ch > 0 && isspace(ch)) {
+ read_stream(inp);
+ ch = peek_stream(inp);
+ }
+ return ch;
}
static void read_errno_param(InputStream * inp, void * x) {
@@ -953,7 +960,7 @@ int read_errno(InputStream * inp) {
return 0;
}
check_char(ch, '{');
- if (peek_stream(inp) == '}') {
+ if (json_peek(inp) == '}') {
read_stream(inp);
}
else {
diff --git a/agent/tcf/framework/json.h b/agent/tcf/framework/json.h
index cd44377b..9ed0670c 100644
--- a/agent/tcf/framework/json.h
+++ b/agent/tcf/framework/json.h
@@ -58,6 +58,9 @@ extern void json_skip_object(InputStream * inp);
/* Read one char and check that it matches 'ch' */
extern void json_test_char(InputStream * inp, int ch);
+/* Peek one char after skipping all whitespaces */
+extern int json_peek(InputStream * inp);
+
extern void json_write_ulong(OutputStream * out, unsigned long n);
extern void json_write_long(OutputStream * out, long n);
extern void json_write_uint64(OutputStream * out, uint64_t n);
diff --git a/agent/tcf/framework/protocol.c b/agent/tcf/framework/protocol.c
index 1227c635..3e1228aa 100644
--- a/agent/tcf/framework/protocol.c
+++ b/agent/tcf/framework/protocol.c
@@ -580,7 +580,7 @@ static void event_locator_hello(Channel * c) {
c->out.supports_zero_copy = 0;
do ch = read_stream(&c->inp);
- while (isspace(ch));
+ while (ch > 0 && isspace(ch));
if (ch != '[') exception(ERR_PROTOCOL);
if (peek_stream(&c->inp) == ']') {
read_stream(&c->inp);
@@ -597,7 +597,7 @@ static void event_locator_hello(Channel * c) {
}
list[cnt++] = service;
do ch = read_stream(&c->inp);
- while (isspace(ch));
+ while (ch > 0 && isspace(ch));
if (ch == ',') continue;
if (ch == ']') break;
free_string_list(cnt, list);
diff --git a/agent/tcf/services/discovery.c b/agent/tcf/services/discovery.c
index dc7b62f6..9adc69aa 100644
--- a/agent/tcf/services/discovery.c
+++ b/agent/tcf/services/discovery.c
@@ -107,7 +107,7 @@ static void command_redirect(char * token, Channel * c) {
int free_ps = 0;
assert(c->state == ChannelStateConnected);
- if (peek_stream(&c->inp) == '{') {
+ if (json_peek(&c->inp) == '{') {
ps = peer_server_alloc();
json_read_struct(&c->inp, read_peer_attr, ps);
free_ps = 1;
diff --git a/agent/tcf/services/symbols.c b/agent/tcf/services/symbols.c
index a345dfc0..ae1db718 100644
--- a/agent/tcf/services/symbols.c
+++ b/agent/tcf/services/symbols.c
@@ -436,7 +436,7 @@ static void command_find_by_name_args(char * token, Channel * c, CommandFindByNa
args->ip = 0;
json_read_string(&c->inp, args->id, sizeof(args->id));
json_test_char(&c->inp, MARKER_EOA);
- if (peek_stream(&c->inp) != '"' && peek_stream(&c->inp) != 'n') {
+ if (json_peek(&c->inp) != '"' && json_peek(&c->inp) != 'n') {
args->ip = (ContextAddress)json_read_uint64(&c->inp);
json_test_char(&c->inp, MARKER_EOA);
}
diff --git a/agent/tcf/services/symbols_proxy.c b/agent/tcf/services/symbols_proxy.c
index e7b036d4..bd04359d 100644
--- a/agent/tcf/services/symbols_proxy.c
+++ b/agent/tcf/services/symbols_proxy.c
@@ -554,7 +554,7 @@ static char ** string_to_symbol_list(char * id, int * cnt) {
static char ** read_symbol_list(InputStream * inp, int * id_cnt) {
char id[256];
- if (peek_stream(inp) == '[') return json_read_alloc_string_array(inp, id_cnt);
+ if (json_peek(inp) == '[') return json_read_alloc_string_array(inp, id_cnt);
json_read_string(inp, id, sizeof(id));
return string_to_symbol_list(id, id_cnt);
}

Back to the top