From 71404a21e0937944e47a760e8736905c75f903ea Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Thu, 2 Jan 2014 16:03:59 +0100 Subject: [PATCH] fix bug #66388 (Crash on POST with Content-Length:0 and untouched body) --- php_http_client_curl.c | 15 ++++++++++++--- tests/bug66388.phpt | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 tests/bug66388.phpt diff --git a/php_http_client_curl.c b/php_http_client_curl.c index 77c6123..3b96cf4 100644 --- a/php_http_client_curl.c +++ b/php_http_client_curl.c @@ -176,9 +176,13 @@ static size_t php_http_curle_read_callback(void *data, size_t len, size_t n, voi { php_http_message_body_t *body = ctx; - if (body) { - TSRMLS_FETCH_FROM_CTX(body->ts); - return php_stream_read(php_http_message_body_stream(body), data, len * n); + if (body && body->stream_id) { + php_stream *s = php_http_message_body_stream(body); + + if (s) { + TSRMLS_FETCH_FROM_CTX(body->ts); + return php_stream_read(s, data, len * n); + } else abort(); } return 0; } @@ -1504,6 +1508,11 @@ static STATUS php_http_client_curl_handler_prepare(php_http_client_curl_handler_ curl_easy_setopt(curl->handle, CURLOPT_READDATA, msg->body); curl_easy_setopt(curl->handle, CURLOPT_INFILESIZE, body_size); curl_easy_setopt(curl->handle, CURLOPT_POSTFIELDSIZE, body_size); + } else { + curl_easy_setopt(curl->handle, CURLOPT_IOCTLDATA, NULL); + curl_easy_setopt(curl->handle, CURLOPT_READDATA, NULL); + curl_easy_setopt(curl->handle, CURLOPT_INFILESIZE, 0L); + curl_easy_setopt(curl->handle, CURLOPT_POSTFIELDSIZE, 0L); } php_http_options_apply(&php_http_curle_options, enqueue->options, curl); diff --git a/tests/bug66388.phpt b/tests/bug66388.phpt new file mode 100644 index 0000000..ac0bff3 --- /dev/null +++ b/tests/bug66388.phpt @@ -0,0 +1,32 @@ +--TEST-- +Bug #66388 (Crash on POST with Content-Length:0 and untouched body) +--SKIPIF-- + +--FILE-- + 0 + ) +); +$client->enqueue($request); +echo $client->send()->getResponse()->getResponseCode(); + +?> + +===DONE=== +--EXPECT-- +Test +401 +===DONE=== -- 2.30.2