asterisk/channels
Mark Michelson 35a98161df 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
48698a5e21 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
2015-08-03 11:23:29 -05:00
..
dahdi Modules: Make ast_module_info->self available to auxiliary sources. 2015-05-04 20:47:01 -04:00
iax2 git migration: Refactor the ASTERISK_FILE_VERSION macro 2015-04-13 03:48:57 -04:00
misdn Makefile: Remove coverage files on 'make clean' 2015-07-04 07:47:06 -05:00
pjsip git migration: Refactor the ASTERISK_FILE_VERSION macro 2015-04-13 03:48:57 -04:00
sip Modules: Make ast_module_info->self available to auxiliary sources. 2015-05-04 20:47:01 -04:00
Makefile Makefile: Remove coverage files on 'make clean' 2015-07-04 07:47:06 -05:00
chan_alsa.c AST_MODULE_INFO: Format corrections to the usages of AST_MODULE_INFO macro. 2015-05-13 16:34:23 -05:00
chan_bridge_media.c AST_MODULE_INFO: Format corrections to the usages of AST_MODULE_INFO macro. 2015-05-13 16:34:23 -05:00
chan_console.c AST_MODULE_INFO: Format corrections to the usages of AST_MODULE_INFO macro. 2015-05-13 16:34:23 -05:00
chan_dahdi.c Stasis: Fix unsafe use of stasis_unsubscribe in modules. 2015-05-22 22:30:22 -05:00
chan_dahdi.h chan_dahdi/sig_analog: Fix distinctive ring detection to suck less. 2015-03-06 20:24:58 +00:00
chan_iax2.c Merge "chan_iax2: Prevent deadlock between hangup and sending lagrq/ping" 2015-06-10 12:06:02 -05:00
chan_mgcp.c chan_mgcp: Don't call close on fd -1. 2015-07-02 06:22:18 -05:00
chan_misdn.c git migration: Refactor the ASTERISK_FILE_VERSION macro 2015-04-13 03:48:57 -04:00
chan_motif.c AST_MODULE_INFO: Format corrections to the usages of AST_MODULE_INFO macro. 2015-05-13 16:34:23 -05:00
chan_nbs.c git migration: Refactor the ASTERISK_FILE_VERSION macro 2015-04-13 03:48:57 -04:00
chan_oss.c git migration: Refactor the ASTERISK_FILE_VERSION macro 2015-04-13 03:48:57 -04:00
chan_phone.c git migration: Refactor the ASTERISK_FILE_VERSION macro 2015-04-13 03:48:57 -04:00
chan_phone.h rename DialTone.h to chan_phone.h because chan_phone.c is the only file using it 2008-05-28 20:00:21 +00:00
chan_pjsip.c pjsip: Add rtp_timeout and rtp_timeout_hold endpoint options. 2015-07-24 12:43:43 -03:00
chan_rtp.c git migration: Refactor the ASTERISK_FILE_VERSION macro 2015-04-13 03:48:57 -04:00
chan_sip.c res_http_websocket: Avoid passing strlen() to ast_websocket_write(). 2015-08-03 11:23:29 -05:00
chan_skinny.c Fix unsafe uses of ast_context pointers. 2015-06-08 11:09:57 -04:00
chan_unistim.c AST_MODULE_INFO: Format corrections to the usages of AST_MODULE_INFO macro. 2015-05-13 16:34:23 -05:00
chan_vpb.cc chan_vpb.cc: Fix compiler warning Jenkins found. 2015-07-01 17:25:31 -05:00
console_board.c git migration: Refactor the ASTERISK_FILE_VERSION macro 2015-04-13 03:48:57 -04:00
console_gui.c Multiple revisions 369001-369002 2012-06-15 16:20:16 +00:00
console_video.c git migration: Refactor the ASTERISK_FILE_VERSION macro 2015-04-13 03:48:57 -04:00
console_video.h implement the 'freeze' function for incoming frames; 2008-06-30 15:45:15 +00:00
misdn_config.c git migration: Refactor the ASTERISK_FILE_VERSION macro 2015-04-13 03:48:57 -04:00
sig_analog.c Logger: Convert 'struct ast_callid' to unsigned int. 2015-03-13 01:12:35 +00:00
sig_analog.h chan_dahdi/sig_analog: Fix distinctive ring detection to suck less. 2015-03-06 20:24:58 +00:00
sig_pri.c Stasis: Fix unsafe use of stasis_unsubscribe in modules. 2015-05-22 22:30:22 -05:00
sig_pri.h sig_pri.h: force_restart_unavailable_chans in wrong scope 2015-07-17 11:02:24 -05:00
sig_ss7.c Logger: Convert 'struct ast_callid' to unsigned int. 2015-03-13 01:12:35 +00:00
sig_ss7.h chan_dahdi: Adds support for major update to libss7. 2014-06-16 18:27:51 +00:00
vcodecs.c Fix printf problems with high ascii characters after r413586 (1.8). 2014-12-17 10:23:32 +00:00
vgrabbers.c git migration: Refactor the ASTERISK_FILE_VERSION macro 2015-04-13 03:48:57 -04:00