From bd0aa4fb04afe0d91b5fac2fc697fafd644cc907 Mon Sep 17 00:00:00 2001 From: Kevin Harwell Date: Mon, 16 Jun 2014 16:22:33 +0000 Subject: 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 --- include/asterisk/http_websocket.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/asterisk/http_websocket.h b/include/asterisk/http_websocket.h index d95e6068e..074ae1202 100644 --- a/include/asterisk/http_websocket.h +++ b/include/asterisk/http_websocket.h @@ -156,6 +156,8 @@ AST_OPTIONAL_API(int, ast_websocket_read, (struct ast_websocket *session, char * /*! * \brief Read a WebSocket frame containing string data. * + * \note The caller is responsible for freeing the output "buf". + * * \param ws pointer to the websocket * \param buf string buffer to populate with data read from socket * \retval -1 on error @@ -164,7 +166,7 @@ AST_OPTIONAL_API(int, ast_websocket_read, (struct ast_websocket *session, char * * \note Once an AST_WEBSOCKET_OPCODE_CLOSE opcode is received the socket will be closed */ AST_OPTIONAL_API(int, ast_websocket_read_string, - (struct ast_websocket *ws, struct ast_str **buf), + (struct ast_websocket *ws, char **buf), { errno = ENOSYS; return -1;}); /*! @@ -189,7 +191,7 @@ AST_OPTIONAL_API(int, ast_websocket_write, (struct ast_websocket *session, enum * \retval -1 if error occurred */ AST_OPTIONAL_API(int, ast_websocket_write_string, - (struct ast_websocket *ws, const struct ast_str *buf), + (struct ast_websocket *ws, const char *buf), { errno = ENOSYS; return -1;}); /*! * \brief Close a WebSocket session by sending a message with the CLOSE opcode and an optional code -- cgit v1.2.3