fix bug #66388 (Crash on POST with Content-Length:0 and untouched body)
authorMichael Wallner <mike@php.net>
Thu, 2 Jan 2014 15:03:59 +0000 (16:03 +0100)
committerMichael Wallner <mike@php.net>
Thu, 2 Jan 2014 15:03:59 +0000 (16:03 +0100)
php_http_client_curl.c
tests/bug66388.phpt [new file with mode: 0644]

index 77c6123e434bbc0b9a3d941f531d48f1474e8a27..3b96cf4dfab60410234046f926b8dcb3efac3711 100644 (file)
@@ -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 (file)
index 0000000..ac0bff3
--- /dev/null
@@ -0,0 +1,32 @@
+--TEST--
+Bug #66388 (Crash on POST with Content-Length:0 and untouched body)
+--SKIPIF--
+<?php php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+
+use http\Client,
+       http\Client\Request;
+
+echo "Test\n";
+
+$client = new Client();
+$request = new Request(
+       'POST',
+       'https://api.twitter.com/oauth/request_token',
+       array(
+               'Content-Length' => 0
+       )
+);
+$client->enqueue($request);
+echo $client->send()->getResponse()->getResponseCode();
+
+?>
+
+===DONE===
+--EXPECT--
+Test
+401
+===DONE===