Changeset 60

Show
Ignore:
Timestamp:
03/01/2005 10:55:47 AM (4 years ago)
Author:
jan
Message:

fixed #25 by setting all duplicates to 400

Location:
trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/configure.in

    r53 r60  
    381381                 tests/docroot/www/go/Makefile \ 
    382382                 tests/docroot/www/indexfile/Makefile \ 
     383                 tests/docroot/www/expire/Makefile \ 
    383384                 lighttpd.spec distribute.sh cygwin/Makefile cygwin/lighttpd.README 
    384385                 openwrt/Makefile openwrt/control openwrt/lighttpd.mk]) 
  • trunk/src/request.c

    r48 r60  
    733733                                                                size_t j; 
    734734                                                                 
     735                                                                if (con_length_set) { 
     736                                                                        con->http_status = 400; 
     737                                                                        con->keep_alive = 0; 
     738                                                                         
     739                                                                        log_error_write(srv, __FILE__, __LINE__, "s",  
     740                                                                                        "duplicate Content-Length-header -> 400"); 
     741                                                                        if (srv->srvconf.log_request_header_on_error) { 
     742                                                                                log_error_write(srv, __FILE__, __LINE__, "Sb", 
     743                                                                                                "request-header:\n", 
     744                                                                                                con->request.request); 
     745                                                                        } 
     746                                                                        return 0; 
     747                                                                } 
     748                                                                 
    735749                                                                if (ds->value->used == 0) SEGFAULT(); 
    736750                                                                 
     
    765779                                                                } 
    766780                                                        } else if (cmp > 0 && 0 == (cmp = buffer_caseless_compare(CONST_BUF_LEN(ds->key), CONST_STR_LEN("Content-Type")))) { 
    767                                                                 con->request.http_content_type = ds->value->ptr; 
     781                                                                /* if dup, only the first one will survive */ 
     782                                                                if (!con->request.http_content_type) { 
     783                                                                        con->request.http_content_type = ds->value->ptr; 
     784                                                                } else { 
     785                                                                        con->http_status = 400; 
     786                                                                        con->keep_alive = 0; 
     787                                                                         
     788                                                                        log_error_write(srv, __FILE__, __LINE__, "s",  
     789                                                                                        "duplicate Content-Type-header -> 400"); 
     790                                                                        if (srv->srvconf.log_request_header_on_error) { 
     791                                                                                log_error_write(srv, __FILE__, __LINE__, "Sb", 
     792                                                                                                "request-header:\n", 
     793                                                                                                con->request.request); 
     794                                                                        } 
     795                                                                        return 0; 
     796                                                                } 
    768797                                                        } else if (cmp > 0 && 0 == (cmp = buffer_caseless_compare(CONST_BUF_LEN(ds->key), CONST_STR_LEN("Expect")))) { 
    769798                                                                /* HTTP 2616 8.2.3  
     
    782811                                                                return 0; 
    783812                                                        } else if (cmp > 0 && 0 == (cmp = buffer_caseless_compare(CONST_BUF_LEN(ds->key), CONST_STR_LEN("Host")))) { 
    784                                                                 con->request.http_host = ds->value; 
     813                                                                if (!con->request.http_host) { 
     814                                                                        con->request.http_host = ds->value; 
     815                                                                } else { 
     816                                                                        con->http_status = 400; 
     817                                                                        con->keep_alive = 0; 
     818                                                                         
     819                                                                        log_error_write(srv, __FILE__, __LINE__, "s",  
     820                                                                                        "duplicate Host-header -> 400"); 
     821                                                                        if (srv->srvconf.log_request_header_on_error) { 
     822                                                                                log_error_write(srv, __FILE__, __LINE__, "Sb", 
     823                                                                                                "request-header:\n", 
     824                                                                                                con->request.request); 
     825                                                                        } 
     826                                                                        return 0; 
     827                                                                } 
    785828                                                        } else if (cmp > 0 && 0 == (cmp = buffer_caseless_compare(CONST_BUF_LEN(ds->key), CONST_STR_LEN("If-Modified-Since")))) { 
    786                                                                 con->request.http_if_modified_since = ds->value->ptr; 
     829                                                                /* if dup, only the first one will survive */ 
     830                                                                if (!con->request.http_if_modified_since) { 
     831                                                                        con->request.http_if_modified_since = ds->value->ptr; 
     832                                                                } else { 
     833                                                                        con->http_status = 400; 
     834                                                                        con->keep_alive = 0; 
     835                                                                         
     836                                                                        log_error_write(srv, __FILE__, __LINE__, "s",  
     837                                                                                        "duplicate If-Modified-Since header -> 400"); 
     838                                                                        if (srv->srvconf.log_request_header_on_error) { 
     839                                                                                log_error_write(srv, __FILE__, __LINE__, "Sb", 
     840                                                                                                "request-header:\n", 
     841                                                                                                con->request.request); 
     842                                                                        } 
     843                                                                        return 0; 
     844                                                                } 
    787845                                                        } else if (cmp > 0 && 0 == (cmp = buffer_caseless_compare(CONST_BUF_LEN(ds->key), CONST_STR_LEN("If-None-Match")))) { 
    788                                                                 con->request.http_if_none_match = ds->value->ptr; 
     846                                                                /* if dup, only the first one will survive */ 
     847                                                                if (!con->request.http_if_none_match) { 
     848                                                                        con->request.http_if_none_match = ds->value->ptr; 
     849                                                                } else { 
     850                                                                        con->http_status = 400; 
     851                                                                        con->keep_alive = 0; 
     852                                                                         
     853                                                                        log_error_write(srv, __FILE__, __LINE__, "s",  
     854                                                                                        "duplicate If-None-Match-header -> 400"); 
     855                                                                        if (srv->srvconf.log_request_header_on_error) { 
     856                                                                                log_error_write(srv, __FILE__, __LINE__, "Sb", 
     857                                                                                                "request-header:\n", 
     858                                                                                                con->request.request); 
     859                                                                        } 
     860                                                                        return 0; 
     861                                                                } 
    789862                                                        } else if (cmp > 0 && 0 == (cmp = buffer_caseless_compare(CONST_BUF_LEN(ds->key), CONST_STR_LEN("Range")))) { 
    790                                                                 /* bytes=.*-.* */ 
    791                                                                  
    792                                                                 if (0 == strncasecmp(ds->value->ptr, "bytes=", 6) && 
    793                                                                     NULL != strchr(ds->value->ptr+6, '-')) { 
     863                                                                if (!con->request.http_range) { 
     864                                                                        /* bytes=.*-.* */ 
     865                                                                 
     866                                                                        if (0 == strncasecmp(ds->value->ptr, "bytes=", 6) && 
     867                                                                            NULL != strchr(ds->value->ptr+6, '-')) { 
     868                                                                                 
     869                                                                                /* if dup, only the first one will survive */ 
     870                                                                                con->request.http_range = ds->value->ptr + 6; 
     871                                                                        } 
     872                                                                } else { 
     873                                                                        con->http_status = 400; 
     874                                                                        con->keep_alive = 0; 
    794875                                                                         
    795                                                                         con->request.http_range = ds->value->ptr + 6; 
     876                                                                        log_error_write(srv, __FILE__, __LINE__, "s",  
     877                                                                                        "duplicate Host-header -> 400"); 
     878                                                                        if (srv->srvconf.log_request_header_on_error) { 
     879                                                                                log_error_write(srv, __FILE__, __LINE__, "Sb", 
     880                                                                                                "request-header:\n", 
     881                                                                                                con->request.request); 
     882                                                                        } 
     883                                                                        return 0; 
    796884                                                                } 
    797885                                                        } 
  • trunk/tests/run-tests.pl

    r56 r60  
    33use strict; 
    44use IO::Socket; 
    5 use Test::More tests => 114; 
     5use Test::More tests => 120; 
    66 
    77 
     
    511511 
    512512 
     513 
     514 
     515 
     516 
     517 
     518 
    513519print "\nLow-Level Response-Header Parsing - Content-Length:\n"; 
    514520@request  = ( <<EOF 
     
    529535 
    530536 
     537 
     538 
     539 
     540 
     541 
     542 
     543 
     544 
    531545print "\nLow-Level Response-Header Parsing - Location:\n"; 
    532546@request  = ( <<EOF 
     
    543557@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 301, 'Location' => 'http://localhost:2048/dummydir/?foo' } ); 
    544558ok(handle_http == 0, 'internal redirect in directory + querystring'); 
     559 
     560 
     561 
     562 
     563 
     564 
     565 
     566 
     567 
     568 
    545569 
    546570 
     
    765789 
    766790 
     791@request  = ( <<EOF 
     792GET / HTTP/1.0 
     793Host: www.example.org 
     794Host: 123.example.org 
     795EOF 
     796 ); 
     797@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ); 
     798ok(handle_http == 0, 'Duplicate Host headers, Bug #25'); 
     799 
     800 
     801@request  = ( <<EOF 
     802GET / HTTP/1.0 
     803Content-Length: 5 
     804Content-Length: 4 
     805EOF 
     806 ); 
     807@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ); 
     808ok(handle_http == 0, 'Duplicate Content-Length headers'); 
     809 
     810@request  = ( <<EOF 
     811GET / HTTP/1.0 
     812Content-Type: 5 
     813Content-Type: 4 
     814EOF 
     815 ); 
     816@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ); 
     817ok(handle_http == 0, 'Duplicate Content-Type headers'); 
     818 
     819@request  = ( <<EOF 
     820GET / HTTP/1.0 
     821Range: bytes=5-6 
     822Range: bytes=5-9 
     823EOF 
     824 ); 
     825@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ); 
     826ok(handle_http == 0, 'Duplicate Range headers'); 
     827 
     828@request  = ( <<EOF 
     829GET / HTTP/1.0 
     830If-None-Match: 5 
     831If-None-Match: 4 
     832EOF 
     833 ); 
     834@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ); 
     835ok(handle_http == 0, 'Duplicate If-None-Match headers'); 
     836 
     837@request  = ( <<EOF 
     838GET / HTTP/1.0 
     839If-Modified-Since: 5 
     840If-Modified-Since: 4 
     841EOF 
     842 ); 
     843@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ); 
     844ok(handle_http == 0, 'Duplicate If-Modified-Since headers'); 
     845 
     846 
    767847 
    768848