[Asterisk-code-review] res http websocket: Fix faulty read logic. (asterisk[master])
Anonymous Coward
asteriskteam at digium.com
Wed Mar 8 10:05:20 CST 2017
Anonymous Coward #1000019 has submitted this change and it was merged. ( 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(-)
Approvals:
Anonymous Coward #1000019: Verified
Matthew Fredrickson: Looks good to me, approved
Joshua Colp: Looks good to me, but someone else must approve
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: merged
Gerrit-Change-Id: Ib4423239828a013d27d7bc477d317d2f02db61ab
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Mark Michelson <mmichelson at digium.com>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Matthew Fredrickson <creslin at digium.com>
More information about the asterisk-code-review
mailing list