diff options
author | Mark Michelson <mmichelson@digium.com> | 2017-03-07 13:38:17 -0600 |
---|---|---|
committer | Mark Michelson <mmichelson@digium.com> | 2017-03-07 13:38:17 -0600 |
commit | 5d0371d7437440482f8d8e42f9fde7288a53159e (patch) | |
tree | bafe154b0128838579b1054216a91e5621c6e1d2 /res/res_http_websocket.c | |
parent | 272259a2c6e952249d07f32948893771e65f3078 (diff) |
res_http_websocket: Fix faulty read logic.
When doing some WebRTC testing, I found that the websocket would
disconnect whenever I attempted to place a call into Asterisk. After
looking into it, I pinpointed the problem to be due to the iostreams
change being merged in.
Under certain circumstances, a call to ast_iostream_read() can return a
negative value. However, in this circumstance, the websocket code was
treating this negative return as if it were a partial read from the
websocket. The expected length would get adjusted by this negative
value, resulting in the expected length being too large.
This patch simply adds an if check to be sure that we are only updating
the expected length of a read when the return from a read is positive.
ASTERISK-26842 #close
Reported by Mark Michelson
Change-Id: Ib4423239828a013d27d7bc477d317d2f02db61ab
Diffstat (limited to 'res/res_http_websocket.c')
-rw-r--r-- | res/res_http_websocket.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/res/res_http_websocket.c b/res/res_http_websocket.c index 84138234e..799eb848f 100644 --- a/res/res_http_websocket.c +++ b/res/res_http_websocket.c @@ -529,10 +529,12 @@ static inline int ws_safe_read(struct ast_websocket *session, char *buf, int len return -1; } } - xlen = xlen - rlen; - rbuf = rbuf + rlen; - if (!xlen) { - break; + if (rlen > 0) { + xlen = xlen - rlen; + rbuf = rbuf + rlen; + if (!xlen) { + break; + } } if (ast_wait_for_input(ast_iostream_get_fd(session->stream), 1000) < 0) { ast_log(LOG_ERROR, "ast_wait_for_input returned err: %s\n", strerror(errno)); |