You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Philip Martin <ph...@wandisco.com> on 2015/01/10 00:35:24 UTC
[PATCH] Serf crash on spurious data between responses
Philip Martin <ph...@wandisco.com> writes:
> While debugging a problem reported on users I accidentally sent an extra
> byte to the client: I sent Content-Length of N and then sent N+1 bytes.
> The first N bytes made a valid response, so serf was happy at that
> stage. When processing the next request the extra byte causes serf to
> attempt to handle the spurious data before any request handler is setup.
> This is with serf 1.3.x@2440.
Here's a patch that causes serf to return an error if this sort of
spurious data is received:
Index: outgoing.c
===================================================================
--- outgoing.c (revision 2445)
+++ outgoing.c (working copy)
@@ -1109,7 +1109,11 @@ static apr_status_t read_from_connection(serf_conn
goto error;
}
- /* Unexpected response from the server */
+ /* Unexpected response from the server. This can happen if
+ * a buggy server sends more than Content-Length data.
+ */
+ status = SERF_ERROR_BAD_HTTP_RESPONSE;
+ goto error;
}
--
Philip Martin | Subversion Committer
WANdisco // *Non-Stop Data*
Re: [serf-dev] Re: [PATCH] Serf crash on spurious data between responses
Posted by Lieven Govaerts <lg...@mobsol.be>.
On Wed, Jan 14, 2015 at 12:54 PM, Philip Martin
<ph...@wandisco.com> wrote:
> Lieven Govaerts <lg...@mobsol.be> writes:
>
>> The easiest way is to use existing tests as a starting point.:
>> - Test test_serf_connection_request_create sends 2 requests and responses.
>> This tests sends two pipelined requests, but you can modifiy it to
>> send the 1st request, then run the serf loop, then send the 2nd
>> request.
>> - To add the extra data to the response of the first request, you'll
>> have to create the raw response body.
>> Have a look at test test_request_timeout, line:
>> Respond(WithRawData(RESPONSE_408, strlen(RESPONSE_408)))
>
> I tried to do this but I cannot use the testsuite to trigger the
> problem. Using the earlier script to trigger the problem in svn I see
> the following order of calls:
>
> Breakpoint 4, serf_connection_request_create (conn=0x465590,
> setup=0x7ffff75ec67a <setup_request_cb>, setup_baton=0x469be0)
> at outgoing.c:1728
> 1728 request = create_request(conn, setup, setup_baton,
> (gdb) c
> Continuing.
>
> Breakpoint 1, setup_request (request=0x46a308) at outgoing.c:776
> 776 serf_connection_t *conn = request->conn;
> (gdb)
> Continuing.
>
> Breakpoint 2, read_from_connection (conn=0x465590) at outgoing.c:1142
> 1142 int close_connection = FALSE;
> (gdb)
> Continuing.
>
> Breakpoint 3, destroy_request (request=0x46a308) at outgoing.c:544
> 544 serf_connection_t *conn = request->conn;
> (gdb)
> Continuing.
>
> Breakpoint 4, serf_connection_request_create (conn=0x465590,
> setup=0x7ffff75ec67a <setup_request_cb>, setup_baton=0x469be0)
> at outgoing.c:1728
> 1728 request = create_request(conn, setup, setup_baton,
> (gdb)
> Continuing.
>
> Breakpoint 2, read_from_connection (conn=0x465590) at outgoing.c:1142
> 1142 int close_connection = FALSE;
>
>
> That is: create, setup, read, destroy for the first request leaving
> spurious data on the socket, followed by create, read for the second
> request. It's the call to read before setup that is the problem and
> that doesn't happen with the test below. I think the reason is that in
> the test both requests are created at the start, rather than creating
> the second request after handling the first. The test needs to separate
> the two requests so that one gets handled before the second is created.
> I'm not sure how best to do that.
>
>
> Index: test/test_context.c
> ===================================================================
> --- test/test_context.c (revision 2472)
> +++ test/test_context.c (working copy)
> @@ -968,6 +968,43 @@ static void test_max_keepalive_requests(CuTest *tc
> CuAssertIntEquals(tc, num_requests, tb->handled_requests->nelts);
> }
>
> +#define RESPONSE_200_SPURIOUS "HTTP/1.1 200 OK" CRLF\
> +"Date: Tue, 13 Jan 2015 22:06:51 GMT" CRLF\
> +"Server: Apache/2.2.22" CRLF\
> +"Content-Length: 27" CRLF\
> +"Content-Type: text/html; charset=UTF-8" CRLF \
> +CRLF\
> +"<html><body></body></html> "
> +
> +static void test_spurious_data(CuTest *tc)
> +{
> + test_baton_t *tb = tc->testBaton;
> + apr_status_t status;
> + handler_baton_t handler_ctx[2];
> + const int num_requests = sizeof(handler_ctx)/sizeof(handler_ctx[0]);
> +
> + setup_test_mock_server(tb);
> + status = setup_test_client_context(tb, NULL, tb->pool);
> + CuAssertIntEquals(tc, APR_SUCCESS, status);
> +
> + Given(tb->mh)
> + GETRequest(URLEqualTo("/"), ChunkedBodyEqualTo("1"),
> + HeaderEqualTo("Host", tb->serv_host))
> + Respond(WithRawData(RESPONSE_200_SPURIOUS,
> + strlen(RESPONSE_200_SPURIOUS)))
> + GETRequest(URLEqualTo("/"), ChunkedBodyEqualTo("2"),
> + HeaderEqualTo("Host", tb->serv_host))
> + Respond(WithCode(200), WithChunkedBody(""))
> + EndGiven
> +
> + create_new_request(tb, &handler_ctx[0], "GET", "/", 1);
> + create_new_request(tb, &handler_ctx[1], "GET", "/", 2);
> + serf_connection_set_max_outstanding_requests(tb->connection, 1);
> +
> + run_client_and_mock_servers_loops_expect_ok(tc, tb, num_requests,
> + handler_ctx, tb->pool);
> +}
Can't test now, but I expect it should be something like this:
create_new_request(tb, &handler_ctx[0], "GET", "/", 1);
run_client_and_mock_servers_loops_expect_ok(tc, tb, 1,
handler_ctx, tb->pool);
create_new_request(tb, &handler_ctx[1], "GET", "/", 2);
run_client_and_mock_servers_loops_expect_ok(tc, tb, 1,
handler_ctx, tb->pool);
I'll have more time this weekend to have a look.
Lieven
> +
> /*****************************************************************************/
> CuSuite *test_context(void)
> {
> @@ -975,6 +1012,7 @@ CuSuite *test_context(void)
>
> CuSuiteSetSetupTeardownCallbacks(suite, test_setup, test_teardown);
>
> +#if 0
> SUITE_ADD_TEST(suite, test_serf_connection_request_create);
> SUITE_ADD_TEST(suite, test_serf_connection_priority_request_create);
> SUITE_ADD_TEST(suite, test_closed_connection);
> @@ -993,6 +1031,9 @@ CuSuite *test_context(void)
> SUITE_ADD_TEST(suite, test_connection_large_response);
> SUITE_ADD_TEST(suite, test_connection_large_request);
> SUITE_ADD_TEST(suite, test_max_keepalive_requests);
> +#else
> + SUITE_ADD_TEST(suite, test_spurious_data);
> +#endif
>
> return suite;
> }
>
> --
> Philip Martin | Subversion Committer
> WANdisco // *Non-Stop Data*
Re: [serf-dev] Re: [PATCH] Serf crash on spurious data between responses
Posted by Philip Martin <ph...@wandisco.com>.
Lieven Govaerts <lg...@mobsol.be> writes:
> The easiest way is to use existing tests as a starting point.:
> - Test test_serf_connection_request_create sends 2 requests and responses.
> This tests sends two pipelined requests, but you can modifiy it to
> send the 1st request, then run the serf loop, then send the 2nd
> request.
> - To add the extra data to the response of the first request, you'll
> have to create the raw response body.
> Have a look at test test_request_timeout, line:
> Respond(WithRawData(RESPONSE_408, strlen(RESPONSE_408)))
I tried to do this but I cannot use the testsuite to trigger the
problem. Using the earlier script to trigger the problem in svn I see
the following order of calls:
Breakpoint 4, serf_connection_request_create (conn=0x465590,
setup=0x7ffff75ec67a <setup_request_cb>, setup_baton=0x469be0)
at outgoing.c:1728
1728 request = create_request(conn, setup, setup_baton,
(gdb) c
Continuing.
Breakpoint 1, setup_request (request=0x46a308) at outgoing.c:776
776 serf_connection_t *conn = request->conn;
(gdb)
Continuing.
Breakpoint 2, read_from_connection (conn=0x465590) at outgoing.c:1142
1142 int close_connection = FALSE;
(gdb)
Continuing.
Breakpoint 3, destroy_request (request=0x46a308) at outgoing.c:544
544 serf_connection_t *conn = request->conn;
(gdb)
Continuing.
Breakpoint 4, serf_connection_request_create (conn=0x465590,
setup=0x7ffff75ec67a <setup_request_cb>, setup_baton=0x469be0)
at outgoing.c:1728
1728 request = create_request(conn, setup, setup_baton,
(gdb)
Continuing.
Breakpoint 2, read_from_connection (conn=0x465590) at outgoing.c:1142
1142 int close_connection = FALSE;
That is: create, setup, read, destroy for the first request leaving
spurious data on the socket, followed by create, read for the second
request. It's the call to read before setup that is the problem and
that doesn't happen with the test below. I think the reason is that in
the test both requests are created at the start, rather than creating
the second request after handling the first. The test needs to separate
the two requests so that one gets handled before the second is created.
I'm not sure how best to do that.
Index: test/test_context.c
===================================================================
--- test/test_context.c (revision 2472)
+++ test/test_context.c (working copy)
@@ -968,6 +968,43 @@ static void test_max_keepalive_requests(CuTest *tc
CuAssertIntEquals(tc, num_requests, tb->handled_requests->nelts);
}
+#define RESPONSE_200_SPURIOUS "HTTP/1.1 200 OK" CRLF\
+"Date: Tue, 13 Jan 2015 22:06:51 GMT" CRLF\
+"Server: Apache/2.2.22" CRLF\
+"Content-Length: 27" CRLF\
+"Content-Type: text/html; charset=UTF-8" CRLF \
+CRLF\
+"<html><body></body></html> "
+
+static void test_spurious_data(CuTest *tc)
+{
+ test_baton_t *tb = tc->testBaton;
+ apr_status_t status;
+ handler_baton_t handler_ctx[2];
+ const int num_requests = sizeof(handler_ctx)/sizeof(handler_ctx[0]);
+
+ setup_test_mock_server(tb);
+ status = setup_test_client_context(tb, NULL, tb->pool);
+ CuAssertIntEquals(tc, APR_SUCCESS, status);
+
+ Given(tb->mh)
+ GETRequest(URLEqualTo("/"), ChunkedBodyEqualTo("1"),
+ HeaderEqualTo("Host", tb->serv_host))
+ Respond(WithRawData(RESPONSE_200_SPURIOUS,
+ strlen(RESPONSE_200_SPURIOUS)))
+ GETRequest(URLEqualTo("/"), ChunkedBodyEqualTo("2"),
+ HeaderEqualTo("Host", tb->serv_host))
+ Respond(WithCode(200), WithChunkedBody(""))
+ EndGiven
+
+ create_new_request(tb, &handler_ctx[0], "GET", "/", 1);
+ create_new_request(tb, &handler_ctx[1], "GET", "/", 2);
+ serf_connection_set_max_outstanding_requests(tb->connection, 1);
+
+ run_client_and_mock_servers_loops_expect_ok(tc, tb, num_requests,
+ handler_ctx, tb->pool);
+}
+
/*****************************************************************************/
CuSuite *test_context(void)
{
@@ -975,6 +1012,7 @@ CuSuite *test_context(void)
CuSuiteSetSetupTeardownCallbacks(suite, test_setup, test_teardown);
+#if 0
SUITE_ADD_TEST(suite, test_serf_connection_request_create);
SUITE_ADD_TEST(suite, test_serf_connection_priority_request_create);
SUITE_ADD_TEST(suite, test_closed_connection);
@@ -993,6 +1031,9 @@ CuSuite *test_context(void)
SUITE_ADD_TEST(suite, test_connection_large_response);
SUITE_ADD_TEST(suite, test_connection_large_request);
SUITE_ADD_TEST(suite, test_max_keepalive_requests);
+#else
+ SUITE_ADD_TEST(suite, test_spurious_data);
+#endif
return suite;
}
--
Philip Martin | Subversion Committer
WANdisco // *Non-Stop Data*
Re: [serf-dev] Re: [PATCH] Serf crash on spurious data between responses
Posted by Philip Martin <ph...@wandisco.com>.
Philip Martin <ph...@wandisco.com> writes:
> $ valgrind -q test/test_all
> ==11901== Invalid read of size 8
> ==11901== at 0x403E7CF: serf_config_get_object (config_store.c:278)
> ==11901== by 0x403F88A: serf__log (logging.c:146)
> ==11901== by 0x4048E79: serf_log_wrapped_readline (log_wrapper_buckets.c:56)
> ==11901== by 0x41546E: serf_mock_sock_readline (mock_sock_buckets.c:44)
> ==11901== by 0x40443BA: serf_barrier_readline (barrier_buckets.c:54)
> ==11901== by 0x404500D: serf_linebuf_fetch (buckets.c:515)
> ==11901== by 0x404A132: fetch_line (response_buckets.c:124)
> ==11901== by 0x404A475: run_machine (response_buckets.c:235)
> ==11901== by 0x404A8FB: wait_for_body (response_buckets.c:365)
> ==11901== by 0x404AA0F: serf_response_read (response_buckets.c:424)
> ==11901== by 0x406ECB: handle_response (test_util.c:246)
> ==11901== by 0x4041791: handle_response (outgoing.c:1049)
> ==11901== Address 0xd is not stack'd, malloc'd or (recently) free'd
This is caused by serf__bucket_log_wrapper_create failing to intialize
log_wrapped_context_t.context. Initialize to NULL?
Index: buckets/log_wrapper_buckets.c
===================================================================
--- buckets/log_wrapper_buckets.c (revision 2464)
+++ buckets/log_wrapper_buckets.c (working copy)
@@ -168,6 +168,7 @@ serf_bucket_t *serf__bucket_log_wrapper_create(ser
ctx->old_type = wrapped->type;
ctx->prefix = prefix;
+ ctx->config = NULL;
/* Construct the new extended bucket. */
bkt->wrapped_bkt.type = bkt_type;
That allows the testsuite to get further, it now crashes in
test_ssl_renegotiate():
$ test/test_all
Out of memory
Aborted
$ valgrind -q --num-callers=20 test/test_all
==18268== Conditional jump or move depends on uninitialised value(s)
==18268== at 0x4DB0D87: ASN1_get_object (asn1_lib.c:107)
==18268== by 0x4DB1120: asn1_GetSequence (asn1_lib.c:319)
==18268== by 0x4A67118: d2i_SSL_SESSION (ssl_asn1.c:392)
==18268== by 0x4A4B3B7: tls_decrypt_ticket (t1_lib.c:2351)
==18268== by 0x4A4D3C8: tls1_process_ticket (t1_lib.c:2240)
==18268== by 0x4A60C3B: ssl_get_prev_session (ssl_sess.c:482)
==18268== by 0x4A37505: ssl3_get_client_hello (s3_srvr.c:1008)
==18268== by 0x4A3BE50: ssl3_accept (s3_srvr.c:357)
==18268== by 0x4A466E8: ssl3_read_bytes (s3_pkt.c:1343)
==18268== by 0x4A435F1: ssl3_read_internal (s3_lib.c:4247)
==18268== by 0x42594C: sslSocketRead (MockHTTP_server.c:2600)
==18268== by 0x420F93: readFromSocket (MockHTTP_server.c:365)
==18268== by 0x421368: buffSktPeek (MockHTTP_server.c:457)
==18268== by 0x423364: processServer (MockHTTP_server.c:1298)
==18268== by 0x423FB3: _mhRunServerLoop (MockHTTP_server.c:1600)
==18268== by 0x41D37D: runServerLoop (MockHTTP.c:143)
==18268== by 0x41D3C7: mhRunServerLoop (MockHTTP.c:154)
==18268== by 0x40772E: run_client_and_mock_servers_loops (test_util.c:499)
==18268== by 0x41B6A7: test_ssl_renegotiate (test_ssl.c:1764)
==18268== by 0x405F0C: CuTestRun (CuTest.c:173)
--
Philip Martin | Subversion Committer
WANdisco // *Non-Stop Data*
Re: [serf-dev] Re: [PATCH] Serf crash on spurious data between responses
Posted by Philip Martin <ph...@codematters.co.uk>.
Philip Martin <ph...@wandisco.com> writes:
> Lieven Govaerts <lg...@mobsol.be> writes:
>
>> Is there a reason you specifically mention pipelined here? The first
>> response has been handled so it's just synchronous communication.
>
> The point is that the client reads data from the server before sending
> the second response. If the client were to close/reopen the connection
> that data would get dropped, or at least that is what appears to happen
> as I don't see the bug if the server sends "Connection: close" with the
> first response.
My use of "pipelining" was incorrect here, what I mean is that both
requests have to be sent on the same connection. I suppose it might be
possible to trigger the bug with a single request if the server sends
spurious data before receiving the request, but it might be tricky to
get the timing right.
--
Philip
Re: [serf-dev] Re: [PATCH] Serf crash on spurious data between responses
Posted by Philip Martin <ph...@wandisco.com>.
Lieven Govaerts <lg...@mobsol.be> writes:
> On Mon, Jan 12, 2015 at 12:22 PM, Philip Martin
>>
>> I'm not familiar with serf's testsuite. The scenario:
>>
>> - client sends first request
>> - server sends response
>> - server sends extra data, say '\n'
>> - client handles first request
>> - client creates a second request
>> - client calls serf to send second, pipelined, request
> Is there a reason you specifically mention pipelined here? The first
> response has been handled so it's just synchronous communication.
The point is that the client reads data from the server before sending
the second response. If the client were to close/reopen the connection
that data would get dropped, or at least that is what appears to happen
as I don't see the bug if the server sends "Connection: close" with the
first response.
>> How do I go about writing such a test?
>
> The easiest way is to use existing tests as a starting point.:
I can't run the tests at all on my machine:
$ test/test_all
Segmentation fault
$ valgrind -q test/test_all
==11901== Invalid read of size 8
==11901== at 0x403E7CF: serf_config_get_object (config_store.c:278)
==11901== by 0x403F88A: serf__log (logging.c:146)
==11901== by 0x4048E79: serf_log_wrapped_readline (log_wrapper_buckets.c:56)
==11901== by 0x41546E: serf_mock_sock_readline (mock_sock_buckets.c:44)
==11901== by 0x40443BA: serf_barrier_readline (barrier_buckets.c:54)
==11901== by 0x404500D: serf_linebuf_fetch (buckets.c:515)
==11901== by 0x404A132: fetch_line (response_buckets.c:124)
==11901== by 0x404A475: run_machine (response_buckets.c:235)
==11901== by 0x404A8FB: wait_for_body (response_buckets.c:365)
==11901== by 0x404AA0F: serf_response_read (response_buckets.c:424)
==11901== by 0x406ECB: handle_response (test_util.c:246)
==11901== by 0x4041791: handle_response (outgoing.c:1049)
==11901== Address 0xd is not stack'd, malloc'd or (recently) free'd
0x000000000403e7cf in serf_config_get_object (config=0x40700a0, key=268435457,
value=0xffefffc10) at config_store.c:278
278 config_entry_t *iter = target->first;
(gdb) p config[0]
$1 = {conn_pool = 0x0, ctx_pool = 0x412b038, per_context = 0x5,
per_host = 0x40701c8, per_conn = 0x100100}
(gdb) p target
$2 = (serf__config_hdr_t *) 0x5
--
Philip Martin | Subversion Committer
WANdisco // *Non-Stop Data*
Re: [serf-dev] Re: [PATCH] Serf crash on spurious data between responses
Posted by Lieven Govaerts <lg...@mobsol.be>.
On Mon, Jan 12, 2015 at 12:22 PM, Philip Martin
<ph...@wandisco.com> wrote:
> Lieven Govaerts <lg...@mobsol.be> writes:
>
>> You're trying to capture the situation where serf has:
>> - finished writing a request ( req_bkt == NULL && writing_started )
>> - has no more requests in the pending queue
>> - and receives actual bytes of data.
>> Right?
>>
>> Looks like your patch is a correct way to fix the problem. Some
>> comments would be welcome, and if you have the time a test.
>
> I'm not familiar with serf's testsuite. The scenario:
>
> - client sends first request
> - server sends response
> - server sends extra data, say '\n'
> - client handles first request
> - client creates a second request
> - client calls serf to send second, pipelined, request
Is there a reason you specifically mention pipelined here? The first
response has been handled so it's just synchronous communication.
> - serf reads extra data
> - serf attempts to pass the extra data to client's callbacks
>
> At this point serf has not called setup_request so although the client
> has created a request is not ready to receive data.
Ok, clear.
> How do I go about writing such a test?
The easiest way is to use existing tests as a starting point.:
- Test test_serf_connection_request_create sends 2 requests and responses.
This tests sends two pipelined requests, but you can modifiy it to
send the 1st request, then run the serf loop, then send the 2nd
request.
- To add the extra data to the response of the first request, you'll
have to create the raw response body.
Have a look at test test_request_timeout, line:
Respond(WithRawData(RESPONSE_408, strlen(RESPONSE_408)))
hth,
Lieven
>
> --
> Philip Martin | Subversion Committer
> WANdisco // *Non-Stop Data*
>
Re: [serf-dev] Re: [PATCH] Serf crash on spurious data between responses
Posted by Philip Martin <ph...@wandisco.com>.
Lieven Govaerts <lg...@mobsol.be> writes:
> You're trying to capture the situation where serf has:
> - finished writing a request ( req_bkt == NULL && writing_started )
> - has no more requests in the pending queue
> - and receives actual bytes of data.
> Right?
>
> Looks like your patch is a correct way to fix the problem. Some
> comments would be welcome, and if you have the time a test.
I'm not familiar with serf's testsuite. The scenario:
- client sends first request
- server sends response
- server sends extra data, say '\n'
- client handles first request
- client creates a second request
- client calls serf to send second, pipelined, request
- serf reads extra data
- serf attempts to pass the extra data to client's callbacks
At this point serf has not called setup_request so although the client
has created a request is not ready to receive data. How do I go about
writing such a test?
--
Philip Martin | Subversion Committer
WANdisco // *Non-Stop Data*
Re: [serf-dev] Re: [PATCH] Serf crash on spurious data between responses
Posted by Lieven Govaerts <lg...@mobsol.be>.
Hi,
On Sat, Jan 10, 2015 at 1:07 PM, Philip Martin
<ph...@wandisco.com> wrote:
> Philip Martin <ph...@wandisco.com> writes:
>
>> Philip Martin <ph...@wandisco.com> writes:
>>
>>> While debugging a problem reported on users I accidentally sent an extra
>>> byte to the client: I sent Content-Length of N and then sent N+1 bytes.
>>> The first N bytes made a valid response, so serf was happy at that
>>> stage. When processing the next request the extra byte causes serf to
>>> attempt to handle the spurious data before any request handler is setup.
>>> This is with serf 1.3.x@2440.
>>
>> Here's a patch that causes serf to return an error if this sort of
>> spurious data is received:
>>
>> Index: outgoing.c
>> ===================================================================
>> --- outgoing.c (revision 2445)
>> +++ outgoing.c (working copy)
>> @@ -1109,7 +1109,11 @@ static apr_status_t read_from_connection(serf_conn
>> goto error;
>> }
>>
>> - /* Unexpected response from the server */
>> + /* Unexpected response from the server. This can happen if
>> + * a buggy server sends more than Content-Length data.
>> + */
>> + status = SERF_ERROR_BAD_HTTP_RESPONSE;
>> + goto error;
>>
>> }
>
> That breaks HTTPS negotiation. This works:
Does serf-'s test suite capture this situation?
What do you see here? I suppose status == APR_SUCCESS with 0 bytes of data?
>
> Index: outgoing.c
> ===================================================================
> --- outgoing.c (revision 2445)
> +++ outgoing.c (working copy)
> @@ -1109,8 +1109,14 @@
> goto error;
> }
>
> - /* Unexpected response from the server */
> -
> + if (!request->req_bkt) {
> + /* Unexpected response from the server. This can happen if
> + * a buggy server sends more than Content-Length data.
> + */
> + status = SERF_ERROR_BAD_HTTP_RESPONSE;
> + goto error;
> + }
> +
> }
>
> /* If the request doesn't have a response bucket, then call the
You're trying to capture the situation where serf has:
- finished writing a request ( req_bkt == NULL && writing_started )
- has no more requests in the pending queue
- and receives actual bytes of data.
Right?
Looks like your patch is a correct way to fix the problem. Some
comments would be welcome, and if you have the time a test.
I should have some time this weekend to have a go at a test and commit.
Lieven
Re: [PATCH] Serf crash on spurious data between responses
Posted by Philip Martin <ph...@wandisco.com>.
Philip Martin <ph...@wandisco.com> writes:
> Philip Martin <ph...@wandisco.com> writes:
>
>> While debugging a problem reported on users I accidentally sent an extra
>> byte to the client: I sent Content-Length of N and then sent N+1 bytes.
>> The first N bytes made a valid response, so serf was happy at that
>> stage. When processing the next request the extra byte causes serf to
>> attempt to handle the spurious data before any request handler is setup.
>> This is with serf 1.3.x@2440.
>
> Here's a patch that causes serf to return an error if this sort of
> spurious data is received:
>
> Index: outgoing.c
> ===================================================================
> --- outgoing.c (revision 2445)
> +++ outgoing.c (working copy)
> @@ -1109,7 +1109,11 @@ static apr_status_t read_from_connection(serf_conn
> goto error;
> }
>
> - /* Unexpected response from the server */
> + /* Unexpected response from the server. This can happen if
> + * a buggy server sends more than Content-Length data.
> + */
> + status = SERF_ERROR_BAD_HTTP_RESPONSE;
> + goto error;
>
> }
That breaks HTTPS negotiation. This works:
Index: outgoing.c
===================================================================
--- outgoing.c (revision 2445)
+++ outgoing.c (working copy)
@@ -1109,8 +1109,14 @@
goto error;
}
- /* Unexpected response from the server */
-
+ if (!request->req_bkt) {
+ /* Unexpected response from the server. This can happen if
+ * a buggy server sends more than Content-Length data.
+ */
+ status = SERF_ERROR_BAD_HTTP_RESPONSE;
+ goto error;
+ }
+
}
/* If the request doesn't have a response bucket, then call the
--
Philip Martin | Subversion Committer
WANdisco // *Non-Stop Data*