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
pull/7/head
Mark Michelson 8 years ago
parent 272259a2c6
commit 5d0371d743

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

Loading…
Cancel
Save