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
This commit is contained in:
Kevin Harwell
2014-06-16 16:22:33 +00:00
parent a1e0a5e4b0
commit bd0aa4fb04
3 changed files with 21 additions and 22 deletions

View File

@@ -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;
}