Skip to content

Commit 09e7877

Browse files
committed
[tcp] fixed potential buffer overflow due to insane large Content-Len values
Check and limit the Content-Lenght to the size of the reading buffer, makes no sense to accept anything higher.
1 parent 80d10b5 commit 09e7877

3 files changed

Lines changed: 21 additions & 0 deletions

File tree

modules/janus/ws_handshake_common.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,6 +1164,13 @@ static int janus_ws_read_http(janus_connection *c, struct tcp_req *r)
11641164
case '8':
11651165
case '9':
11661166
r->content_len=r->content_len*10+(*p-'0');
1167+
if (r->content_len>=TCP_BUF_SIZE) {
1168+
LM_ERR("Content-Length value %d bigger than the "
1169+
"reading buffer\n", r->content_len);
1170+
r->error = TCP_REQ_BAD_LEN;
1171+
r->state = H_SKIP;
1172+
r->content_len = 0;
1173+
}
11671174
break;
11681175
case '\r':
11691176
case ' ':

modules/proto_ws/ws_handshake_common.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1617,6 +1617,13 @@ static int ws_read_http(struct tcp_connection *c, struct tcp_req *r)
16171617
case '8':
16181618
case '9':
16191619
r->content_len=r->content_len*10+(*p-'0');
1620+
if (r->content_len>=TCP_BUF_SIZE) {
1621+
LM_ERR("Content-Length value %d bigger than the "
1622+
"reading buffer\n", r->content_len);
1623+
r->error = TCP_REQ_BAD_LEN;
1624+
r->state = H_SKIP;
1625+
r->content_len = 0;
1626+
}
16201627
break;
16211628
case '\r':
16221629
case ' ':

net/proto_tcp/tcp_common.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,13 @@ inline static void tcp_parse_headers(struct tcp_req *r,
295295
case '8':
296296
case '9':
297297
r->content_len=r->content_len*10+(*p-'0');
298+
if (r->content_len>=TCP_BUF_SIZE) {
299+
LM_ERR("Content-Length value %d bigger than the "
300+
"reading buffer\n", r->content_len);
301+
r->error = TCP_REQ_BAD_LEN;
302+
r->state = H_SKIP;
303+
r->content_len = 0;
304+
}
298305
break;
299306
case '\r':
300307
case ' ':

0 commit comments

Comments
 (0)