@@ -524,11 +524,10 @@ static struct request_s *process_request (struct conn_s *connptr,
524524 * server headers can be processed.
525525 * - rjkaes
526526 */
527- static int pull_client_data (struct conn_s * connptr , long int length , int iehack )
527+ static int pull_client_data (struct conn_s * connptr , long int length )
528528{
529529 char * buffer ;
530530 ssize_t len ;
531- int ret ;
532531
533532 buffer =
534533 (char * ) safemalloc (min (MAXBUFFSIZE , (unsigned long int ) length ));
@@ -549,43 +548,6 @@ static int pull_client_data (struct conn_s *connptr, long int length, int iehack
549548 length -= len ;
550549 } while (length > 0 );
551550
552- if (iehack ) {
553- /*
554- * BUG FIX: Internet Explorer will leave two bytes (carriage
555- * return and line feed) at the end of a POST message. These
556- * need to be eaten for tinyproxy to work correctly.
557- */
558- ret = socket_nonblocking (connptr -> client_fd );
559- if (ret != 0 ) {
560- log_message (LOG_ERR , "Failed to set the client socket "
561- "to non-blocking: %s" , strerror (errno ));
562- goto ERROR_EXIT ;
563- }
564-
565- len = recv (connptr -> client_fd , buffer , 2 , MSG_PEEK );
566-
567- ret = socket_blocking (connptr -> client_fd );
568- if (ret != 0 ) {
569- log_message (LOG_ERR , "Failed to set the client socket "
570- "to blocking: %s" , strerror (errno ));
571- goto ERROR_EXIT ;
572- }
573-
574- if (len < 0 && errno != EAGAIN )
575- goto ERROR_EXIT ;
576-
577- if ((len == 2 ) && CHECK_CRLF (buffer , len )) {
578- ssize_t bytes_read ;
579-
580- bytes_read = read (connptr -> client_fd , buffer , 2 );
581- if (bytes_read == -1 ) {
582- log_message
583- (LOG_WARNING ,
584- "Could not read two bytes from POST message" );
585- }
586- }
587- }
588-
589551 safefree (buffer );
590552 return 0 ;
591553
@@ -613,8 +575,10 @@ static int pull_client_data_chunked (struct conn_s *connptr) {
613575 }
614576
615577 chunklen = strtol (buffer , (char * * )0 , 16 );
578+ /* prevent negative or huge values causing overflow */
579+ if (chunklen < 0 || chunklen > 0x0fffffff ) goto ERROR_EXIT ;
616580
617- if (pull_client_data (connptr , chunklen + 2 , 0 ) < 0 )
581+ if (pull_client_data (connptr , chunklen + 2 ) < 0 )
618582 goto ERROR_EXIT ;
619583
620584 if (!chunklen ) break ;
@@ -848,7 +812,7 @@ static int is_chunked_transfer (pseudomap *hashofheaders)
848812{
849813 char * data ;
850814 data = pseudomap_find (hashofheaders , "transfer-encoding" );
851- return data ? !strcmp (data , "chunked" ) : 0 ;
815+ return data ? !strcasecmp (data , "chunked" ) : 0 ;
852816}
853817
854818/*
@@ -1007,7 +971,7 @@ process_client_headers (struct conn_s *connptr, pseudomap *hashofheaders)
1007971PULL_CLIENT_DATA :
1008972 if (connptr -> content_length .client > 0 ) {
1009973 ret = pull_client_data (connptr ,
1010- connptr -> content_length .client , 1 );
974+ connptr -> content_length .client );
1011975 } else if (connptr -> content_length .client == -2 )
1012976 ret = pull_client_data_chunked (connptr );
1013977
@@ -1194,8 +1158,8 @@ static int process_server_headers (struct conn_s *connptr)
11941158}
11951159
11961160/*
1197- * Switch the sockets into nonblocking mode and begin relaying the bytes
1198- * between the two connections. We continue to use the buffering code
1161+ * Begin relaying the bytes between the two connections.
1162+ * We continue to use the buffering code
11991163 * since we want to be able to buffer a certain amount for slower
12001164 * connections (as this was the reason why I originally modified
12011165 * tinyproxy oh so long ago...)
@@ -1268,14 +1232,6 @@ static void relay_connection (struct conn_s *connptr)
12681232 /*
12691233 * Try to send any remaining data to the server if we can.
12701234 */
1271- ret = socket_blocking (connptr -> server_fd );
1272- if (ret != 0 ) {
1273- log_message (LOG_ERR ,
1274- "Failed to set server socket to blocking: %s" ,
1275- strerror (errno ));
1276- return ;
1277- }
1278-
12791235 while (buffer_size (connptr -> cbuffer ) > 0 ) {
12801236 if (write_buffer (connptr -> server_fd , connptr -> cbuffer ) < 0 )
12811237 break ;
@@ -1572,16 +1528,9 @@ static void auth_error(struct conn_s *connptr, int code) {
15721528}
15731529
15741530/*
1575- * This is the main drive for each connection. As you can tell, for the
1576- * first few steps we are using a blocking socket. If you remember the
1577- * older tinyproxy code, this use to be a very confusing state machine.
1578- * Well, no more! :) The sockets are only switched into nonblocking mode
1579- * when we start the relay portion. This makes most of the original
1580- * tinyproxy code, which was confusing, redundant. Hail progress.
1581- * - rjkaes
1582-
1531+ * This is the main drive for each connection.
15831532 * this function is called directly from child_thread() with the newly
1584- * received fd from accept().
1533+ * received fd from accept().
15851534 */
15861535void handle_connection (struct conn_s * connptr , union sockaddr_union * addr )
15871536{
0 commit comments