fix segfault when initializing a request message with a body
authorMichael Wallner <mike@php.net>
Tue, 16 Jul 2013 08:46:01 +0000 (08:46 +0000)
committerMichael Wallner <mike@php.net>
Tue, 16 Jul 2013 08:46:01 +0000 (08:46 +0000)
TODO: convert phpunit tests to PHPTs

php_http_client_request.c
php_http_message.c
phpunit/CookieTest.php

index 2d427a3dd17819624f0458a75eb429cdc27ab4c9..86843e6428b8d6199b50450b2e79de24db29df7c 100644 (file)
@@ -34,10 +34,7 @@ static PHP_METHOD(HttpClientRequest, __construct)
                        php_http_message_body_object_t *body_obj = NULL;
 
                        if (zbody) {
-                               body_obj = zend_object_store_get_object(zbody TSRMLS_CC);
-                               Z_OBJ_ADDREF_P(zbody);
-                               obj->body->zv = Z_OBJVAL_P(zbody);
-                               php_http_message_body_addref(body_obj->body);
+                               php_http_message_object_set_body(obj, zbody TSRMLS_CC);
                        }
 
                        if (obj->message) {
index 80c488e6165ce9572a5bb1ae6e68a243ed3162d5..68ba91adb09ee207ec28ad894ce7f0fd58eb5fd2 100644 (file)
@@ -774,9 +774,12 @@ STATUS php_http_message_object_set_body(php_http_message_object_t *msg_obj, zval
        if (msg_obj->body) {
                zend_objects_store_del_ref_by_handle(msg_obj->body->zv.handle TSRMLS_CC);
        }
-       php_http_message_body_free(&msg_obj->message->body);
-
-       msg_obj->message->body = php_http_message_body_init(&body_obj->body, NULL TSRMLS_CC);
+       if (msg_obj->message) {
+               php_http_message_body_free(&msg_obj->message->body);
+               msg_obj->message->body = php_http_message_body_init(&body_obj->body, NULL TSRMLS_CC);
+       } else {
+               msg_obj->message = php_http_message_init(NULL, 0, php_http_message_body_init(&body_obj->body, NULL TSRMLS_CC) TSRMLS_CC);
+       }
        msg_obj->body = body_obj;
 
        if (tmp) {
index 11342adf6dfe763eb1090b60b5fd3cbe401c3158..d569c75f88c02cc464824ce774d1644a7acc8104 100644 (file)
@@ -1,5 +1,7 @@
 <?php
 
+ini_set("date.timezone", "Europe/Vienna");
+
 class CookieTest extends PHPUnit_Framework_TestCase {
     function testEmpty() {
         $c = new http\Cookie;