Changeset 2cbdbc878df61686200447e11e55f8fc09ace496
- Timestamp:
- 15/09/07 15:43:38
(1 year ago)
- Author:
- Rémi Denis-Courmont <rem@videolan.org>
- git-committer:
- Rémi Denis-Courmont <rem@videolan.org> 1189863818 +0000
- git-parent:
[4832c1e5dd8d1b8a435fd410ae6afeb2ec26ca32]
- git-author:
- Rémi Denis-Courmont <rem@videolan.org> 1189863818 +0000
- Message:
Don't crash if a client sends an overly large header
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r05a6622 |
r2cbdbc8 |
|
| 536 | 536 | { |
|---|
| 537 | 537 | char *p = (char *)answer->p_body; |
|---|
| | 538 | |
|---|
| | 539 | /* Looks for end of header (i.e. one empty line) */ |
|---|
| 538 | 540 | while ( (p = strchr( p, '\r' )) != NULL ) |
|---|
| 539 | 541 | { |
|---|
| … | … | |
| 544 | 546 | } |
|---|
| 545 | 547 | } |
|---|
| | 548 | |
|---|
| 546 | 549 | if( p != NULL ) |
|---|
| 547 | 550 | { |
|---|
| … | … | |
| 1469 | 1472 | } |
|---|
| 1470 | 1473 | |
|---|
| | 1474 | |
|---|
| | 1475 | static const struct |
|---|
| | 1476 | { |
|---|
| | 1477 | const char name[16]; |
|---|
| | 1478 | int i_type; |
|---|
| | 1479 | int i_proto; |
|---|
| | 1480 | } |
|---|
| | 1481 | msg_type[] = |
|---|
| | 1482 | { |
|---|
| | 1483 | { "OPTIONS", HTTPD_MSG_OPTIONS, HTTPD_PROTO_RTSP }, |
|---|
| | 1484 | { "DESCRIBE", HTTPD_MSG_DESCRIBE, HTTPD_PROTO_RTSP }, |
|---|
| | 1485 | { "SETUP", HTTPD_MSG_SETUP, HTTPD_PROTO_RTSP }, |
|---|
| | 1486 | { "PLAY", HTTPD_MSG_PLAY, HTTPD_PROTO_RTSP }, |
|---|
| | 1487 | { "PAUSE", HTTPD_MSG_PAUSE, HTTPD_PROTO_RTSP }, |
|---|
| | 1488 | { "GET_PARAMETER", HTTPD_MSG_GETPARAMETER, HTTPD_PROTO_RTSP }, |
|---|
| | 1489 | { "TEARDOWN", HTTPD_MSG_TEARDOWN, HTTPD_PROTO_RTSP }, |
|---|
| | 1490 | { "GET", HTTPD_MSG_GET, HTTPD_PROTO_HTTP }, |
|---|
| | 1491 | { "HEAD", HTTPD_MSG_HEAD, HTTPD_PROTO_HTTP }, |
|---|
| | 1492 | { "POST", HTTPD_MSG_POST, HTTPD_PROTO_HTTP }, |
|---|
| | 1493 | { "", HTTPD_MSG_NONE, HTTPD_PROTO_NONE } |
|---|
| | 1494 | }; |
|---|
| | 1495 | |
|---|
| | 1496 | |
|---|
| 1471 | 1497 | static void httpd_ClientRecv( httpd_client_t *cl ) |
|---|
| 1472 | 1498 | { |
|---|
| … | … | |
| 1475 | 1501 | if( cl->query.i_proto == HTTPD_PROTO_NONE ) |
|---|
| 1476 | 1502 | { |
|---|
| 1477 | | /* enough to see if it's rtp over rtsp or RTSP/HTTP */ |
|---|
| | 1503 | /* enough to see if it's Interleaved RTP over RTSP or RTSP/HTTP */ |
|---|
| 1478 | 1504 | i_len = httpd_NetRecv( cl, &cl->p_buffer[cl->i_buffer], |
|---|
| 1479 | 1505 | 4 - cl->i_buffer ); |
|---|
| … | … | |
| 1485 | 1511 | if( cl->i_buffer >= 4 ) |
|---|
| 1486 | 1512 | { |
|---|
| 1487 | | /*fprintf( stderr, "peek=%4.4s\n", cl->p_buffer );*/ |
|---|
| 1488 | 1513 | /* detect type */ |
|---|
| 1489 | 1514 | if( cl->p_buffer[0] == '$' ) |
|---|
| 1490 | 1515 | { |
|---|
| 1491 | | /* RTSP (rtp over rtsp) */ |
|---|
| | 1516 | /* Interleaved RTP over RTSP */ |
|---|
| 1492 | 1517 | cl->query.i_proto = HTTPD_PROTO_RTSP; |
|---|
| 1493 | 1518 | cl->query.i_type = HTTPD_MSG_CHANNEL; |
|---|
| … | … | |
| 1541 | 1566 | for( ;; ) |
|---|
| 1542 | 1567 | { |
|---|
| | 1568 | if( cl->i_buffer == cl->i_buffer_size ) |
|---|
| | 1569 | { |
|---|
| | 1570 | char *newbuf = realloc( cl->p_buffer, cl->i_buffer_size + 1024 ); |
|---|
| | 1571 | if( newbuf == NULL ) |
|---|
| | 1572 | { |
|---|
| | 1573 | i_len = 0; |
|---|
| | 1574 | break; |
|---|
| | 1575 | } |
|---|
| | 1576 | |
|---|
| | 1577 | cl->p_buffer = newbuf; |
|---|
| | 1578 | cl->i_buffer_size += 1024; |
|---|
| | 1579 | } |
|---|
| | 1580 | |
|---|
| 1543 | 1581 | i_len = httpd_NetRecv (cl, &cl->p_buffer[cl->i_buffer], 1 ); |
|---|
| 1544 | 1582 | if( i_len <= 0 ) |
|---|
| … | … | |
| 1548 | 1586 | cl->i_buffer++; |
|---|
| 1549 | 1587 | |
|---|
| 1550 | | if( cl->i_buffer + 1 >= cl->i_buffer_size ) |
|---|
| 1551 | | { |
|---|
| 1552 | | cl->i_buffer_size += 1024; |
|---|
| 1553 | | cl->p_buffer = realloc( cl->p_buffer, cl->i_buffer_size ); |
|---|
| 1554 | | } |
|---|
| 1555 | 1588 | if( ( cl->i_buffer >= 2 && !memcmp( &cl->p_buffer[cl->i_buffer-2], "\n\n", 2 ) )|| |
|---|
| 1556 | 1589 | ( cl->i_buffer >= 4 && !memcmp( &cl->p_buffer[cl->i_buffer-4], "\r\n\r\n", 4 ) ) ) |
|---|
| … | … | |
| 1574 | 1607 | else |
|---|
| 1575 | 1608 | { |
|---|
| 1576 | | static const struct |
|---|
| 1577 | | { |
|---|
| 1578 | | const char name[16]; |
|---|
| 1579 | | int i_type; |
|---|
| 1580 | | int i_proto; |
|---|
| 1581 | | } |
|---|
| 1582 | | msg_type[] = |
|---|
| 1583 | | { |
|---|
| 1584 | | { "OPTIONS", HTTPD_MSG_OPTIONS, HTTPD_PROTO_RTSP }, |
|---|
| 1585 | | { "DESCRIBE", HTTPD_MSG_DESCRIBE, HTTPD_PROTO_RTSP }, |
|---|
| 1586 | | { "SETUP", HTTPD_MSG_SETUP, HTTPD_PROTO_RTSP }, |
|---|
| 1587 | | { "PLAY", HTTPD_MSG_PLAY, HTTPD_PROTO_RTSP }, |
|---|
| 1588 | | { "PAUSE", HTTPD_MSG_PAUSE, HTTPD_PROTO_RTSP }, |
|---|
| 1589 | | { "GET_PARAMETER", HTTPD_MSG_GETPARAMETER, HTTPD_PROTO_RTSP }, |
|---|
| 1590 | | { "TEARDOWN", HTTPD_MSG_TEARDOWN, HTTPD_PROTO_RTSP }, |
|---|
| 1591 | | |
|---|
| 1592 | | { "GET", HTTPD_MSG_GET, HTTPD_PROTO_HTTP }, |
|---|
| 1593 | | { "HEAD", HTTPD_MSG_HEAD, HTTPD_PROTO_HTTP }, |
|---|
| 1594 | | { "POST", HTTPD_MSG_POST, HTTPD_PROTO_HTTP }, |
|---|
| 1595 | | |
|---|
| 1596 | | { "", HTTPD_MSG_NONE, HTTPD_PROTO_NONE } |
|---|
| 1597 | | }; |
|---|
| 1598 | 1609 | unsigned i; |
|---|
| 1599 | 1610 | |
|---|