[Asterisk-code-review] res http websocket: Fix faulty read logic. (asterisk[master])

Mark Michelson asteriskteam at digium.com
Tue Mar 7 13:42:55 CST 2017


Mark Michelson has uploaded a new change for review. ( https://gerrit.asterisk.org/5137 )

Change subject: res_http_websocket: Fix faulty read logic.
......................................................................

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
---
M res/res_http_websocket.c
1 file changed, 6 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/37/5137/1

diff --git a/res/res_http_websocket.c b/res/res_http_websocket.c
index 8413823..799eb84 100644
--- a/res/res_http_websocket.c
+++ b/res/res_http_websocket.c
@@ -529,10 +529,12 @@
 				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));

-- 
To view, visit https://gerrit.asterisk.org/5137
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib4423239828a013d27d7bc477d317d2f02db61ab
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Mark Michelson <mmichelson at digium.com>



More information about the asterisk-code-review mailing list