summaryrefslogtreecommitdiff
path: root/res/ari
diff options
context:
space:
mode:
authorMark Michelson <mmichelson@digium.com>2015-08-03 11:06:07 -0500
committerMark Michelson <mmichelson@digium.com>2015-08-03 11:06:07 -0500
commit39cc28f6ea2140ad6d561fd4c9e9a66f065cecee (patch)
treeaa48bf19786003d424cfd778bd786e313376ca6c /res/ari
parent20ee33e22e3724c35ab3078c5032b87af5b4920c (diff)
res_http_websocket: Avoid passing strlen() to ast_websocket_write().
We have seen a rash of test failures on a 32-bit build agent. Commit 48698a5e21d7307f61b5fb2bd39fd593bc1423ca solved an obvious problem where we were not encoding a 64-bit value correctly over the wire. This commit, however, did not solve the test failures. In the failing tests, ARI is attempting to send a 537 byte text frame over a websocket. When sending a frame this small, 16 bits are all that is required in order to encode the payload length on the websocket frame. However, ast_websocket_write() thinks that the payload length is greater than 65535 and therefore writes out a 64 bit payload length. Inspecting this payload length, the lower 32 bits are exactly what we would expect it to be, 537 in hex. The upper 32 bits, are junk values that are not expected to be there. In the failure, we are passing the result of strlen() to a function that expects a uint64_t parameter to be passed in. strlen() returns a size_t, which on this 32-bit machine is 32 bits wide. Normally, passing a 32-bit unsigned value to somewhere where a 64-bit unsigned value is expected would cause no problems. In fact, in manual runs of failing tests, this works just fine. However, ast_websocket_write() uses the Asterisk optional API, which means that rather than a simple function call, there are a series of macros that are used for its declaration and implementation. These macros may be causing some sort of error to occur when converting from a 32 bit quantity to a 64 bit quantity. This commit changes the logic by making existing ast_websocket_write() calls use ast_websocket_write_string() instead. Within ast_websocket_write_string(), the 64-bit converted strlen is saved in a local variable, and that variable is passed to ast_websocket_write() instead. Note that this commit message is full of speculation rather than certainty. This is because the observed test failures, while always present in automated test runs, never occur when tests are manually attempted on the same test agent. The idea behind this commit is to fix a theoretical issue by performing changes that should, at the least, cause no harm. If it turns out that this change does not fix the failing tests, then this commit should be reverted. Change-Id: I4458dd87d785ca322b89c152b223a540a3d23e67
Diffstat (limited to 'res/ari')
-rw-r--r--res/ari/ari_websockets.c7
1 files changed, 2 insertions, 5 deletions
diff --git a/res/ari/ari_websockets.c b/res/ari/ari_websockets.c
index f3b764bf1..1d2eacd5b 100644
--- a/res/ari/ari_websockets.c
+++ b/res/ari/ari_websockets.c
@@ -163,9 +163,7 @@ int ast_ari_websocket_session_write(struct ast_ari_websocket_session *session,
#ifdef AST_DEVMODE
if (!session->validator(message)) {
ast_log(LOG_ERROR, "Outgoing message failed validation\n");
- return ast_websocket_write(session->ws_session,
- AST_WEBSOCKET_OPCODE_TEXT, VALIDATION_FAILED,
- strlen(VALIDATION_FAILED));
+ return ast_websocket_write_string(session->ws_session, VALIDATION_FAILED);
}
#endif
@@ -177,8 +175,7 @@ int ast_ari_websocket_session_write(struct ast_ari_websocket_session *session,
}
ast_debug(3, "Examining ARI event: \n%s\n", str);
- if (ast_websocket_write(session->ws_session,
- AST_WEBSOCKET_OPCODE_TEXT, str, strlen(str))) {
+ if (ast_websocket_write_string(session->ws_session, str)) {
ast_log(LOG_NOTICE, "Problem occurred during websocket write, websocket closed\n");
return -1;
}