Changeset 1869

Show
Ignore:
Timestamp:
06/15/2007 02:08:32 PM (16 months ago)
Author:
jan
Message:

fixed remote crash on duplicate header keys with line-wrapping (fixes #1230)

Location:
branches/lighttpd-1.4.x
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • branches/lighttpd-1.4.x/src/request.c

    r1727 r1869  
    284284 
    285285        int done = 0; 
    286  
    287         data_string *ds = NULL; 
    288286 
    289287        /* 
     
    716714                        case '\r': 
    717715                                if (con->parse_request->ptr[i+1] == '\n') { 
     716                                        data_string *ds = NULL; 
     717 
    718718                                        /* End of Headerline */ 
    719719                                        con->parse_request->ptr[i] = '\0'; 
     
    721721 
    722722                                        if (in_folding) { 
    723                                                 if (!ds) { 
     723                                                buffer *key_b; 
     724                                                /** 
     725                                                 * we use a evil hack to handle the line-folding 
     726                                                 *  
     727                                                 * As array_insert_unique() deletes 'ds' in the case of a duplicate 
     728                                                 * ds points somewhere and we get a evil crash. As a solution we keep the old 
     729                                                 * "key" and get the current value from the hash and append us 
     730                                                 * 
     731                                                 * */ 
     732 
     733                                                if (!key || !key_len) { 
    724734                                                        /* 400 */ 
    725735 
     
    738748                                                        return 0; 
    739749                                                } 
    740                                                 buffer_append_string(ds->value, value); 
     750 
     751                                                key_b = buffer_init(); 
     752                                                buffer_copy_string_len(key_b, key, key_len); 
     753 
     754                                                if (NULL != (ds = (data_string *)array_get_element(con->request.headers, key_b->ptr))) { 
     755                                                        buffer_append_string(ds->value, value); 
     756                                                } 
     757 
     758                                                buffer_free(key_b); 
    741759                                        } else { 
    742760                                                int s_len; 
     
    970988                                        is_key = 1; 
    971989                                        value = 0; 
    972                                         key_len = 0; 
     990#if 0 
     991                                        /** 
     992                                         * for Bug 1230 keep the key_len a live 
     993                                         */ 
     994                                        key_len = 0;  
     995#endif 
    973996                                        in_folding = 0; 
    974997                                } else { 
  • branches/lighttpd-1.4.x/tests/core-request.t

    r1374 r1869  
    99use strict; 
    1010use IO::Socket; 
    11 use Test::More tests => 33; 
     11use Test::More tests => 36; 
    1212use LightyTest; 
    1313 
     
    274274ok($tf->handle_http($t) == 0, 'uppercase filenames'); 
    275275 
     276$t->{REQUEST}  = ( <<EOF 
     277GET / HTTP/1.0 
     278Location: foo 
     279Location: foobar 
     280  baz 
     281EOF 
     282 ); 
     283$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ]; 
     284ok($tf->handle_http($t) == 0, '#1209 - duplicate headers with line-wrapping'); 
     285 
     286$t->{REQUEST}  = ( <<EOF 
     287GET / HTTP/1.0 
     288Location:  
     289Location: foobar 
     290  baz 
     291EOF 
     292 ); 
     293$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ]; 
     294ok($tf->handle_http($t) == 0, '#1209 - duplicate headers with line-wrapping - test 2'); 
     295 
     296$t->{REQUEST}  = ( <<EOF 
     297GET / HTTP/1.0 
     298A:  
     299Location: foobar 
     300  baz 
     301EOF 
     302 ); 
     303$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ]; 
     304ok($tf->handle_http($t) == 0, '#1209 - duplicate headers with line-wrapping - test 3'); 
     305 
     306 
     307 
    276308 
    277309ok($tf->stop_proc == 0, "Stopping lighttpd");