summaryrefslogtreecommitdiff
path: root/tests/test_websocket_client.c
diff options
context:
space:
mode:
authorKevin Harwell <kharwell@digium.com>2014-06-16 16:22:33 +0000
committerKevin Harwell <kharwell@digium.com>2014-06-16 16:22:33 +0000
commitbd0aa4fb04afe0d91b5fac2fc697fafd644cc907 (patch)
tree43dd06d444f6725302ed3333c98a451e9c8e9602 /tests/test_websocket_client.c
parenta1e0a5e4b07387bcc59afa7c0ab9f960a389ac15 (diff)
res_http_websocket: read/write string fixup
There was a problem when reading a string from the websocket. It assumed the received data had a null terminator and tried to write the data to an ast_str. This of course could/would read past the end of the given buffer while writing the data to the internal buffer of ast_str. Modified the the code to correctly place a null terminator on the result string. git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@416394 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'tests/test_websocket_client.c')
-rw-r--r--tests/test_websocket_client.c10
1 files changed, 3 insertions, 7 deletions
diff --git a/tests/test_websocket_client.c b/tests/test_websocket_client.c
index 726ee1cfc..dcf1a1773 100644
--- a/tests/test_websocket_client.c
+++ b/tests/test_websocket_client.c
@@ -48,8 +48,8 @@ AST_TEST_DEFINE(websocket_client_create_and_connect)
RAII_VAR(struct ast_websocket *, client, NULL, ao2_cleanup);
enum ast_websocket_result result;
- struct ast_str *write_buf;
- struct ast_str *read_buf;
+ const char write_buf[] = "this is only a test";
+ RAII_VAR(char *, read_buf, NULL, ast_free);
switch (cmd) {
case TEST_INIT:
@@ -62,16 +62,12 @@ AST_TEST_DEFINE(websocket_client_create_and_connect)
break;
}
- write_buf = ast_str_alloca(20);
- read_buf = ast_str_alloca(20);
-
ast_test_validate(test, (client = ast_websocket_client_create(
REMOTE_URL, "echo", NULL, &result)));
- ast_str_set(&write_buf, 0, "this is only a test");
ast_test_validate(test, !ast_websocket_write_string(client, write_buf));
ast_test_validate(test, ast_websocket_read_string(client, &read_buf) > 0);
- ast_test_validate(test, !strcmp(ast_str_buffer(write_buf), ast_str_buffer(read_buf)));
+ ast_test_validate(test, !strcmp(write_buf, read_buf));
return AST_TEST_PASS;
}