- Disallow $HttpMessage->prepend($HttpMessage) causing infinite recursion
authorMichael Wallner <mike@php.net>
Sun, 2 Apr 2006 21:51:01 +0000 (21:51 +0000)
committerMichael Wallner <mike@php.net>
Sun, 2 Apr 2006 21:51:01 +0000 (21:51 +0000)
http_message_object.c
package2.xml

index 7069e6aa50f3c058e1f3623938062ddd5eefafb7..a04438b526faa6f8ceb060f3e7e42bf3e8b74d47 100644 (file)
@@ -1417,6 +1417,8 @@ PHP_METHOD(HttpMessage, detach)
  * Prepends message(s) to the HTTP message.
  *
  * Expects an HttpMessage object as parameter.
+ *
+ * Throws HttpInvalidParamException if the messages are located within the same message chain.
  */
 PHP_METHOD(HttpMessage, prepend)
 {
@@ -1424,6 +1426,20 @@ PHP_METHOD(HttpMessage, prepend)
        zend_bool top = 1;
        
        if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|b", &prepend, http_message_object_ce, &top)) {
+               http_message *msg[2];
+               getObject(http_message_object, obj);
+               getObjectEx(http_message_object, prepend_obj, prepend);
+               
+               /* safety check */
+               for (msg[0] = obj->message; msg[0]; msg[0] = msg[0]->parent) {
+                       for (msg[1] = prepend_obj->message; msg[1]; msg[1] = msg[1]->parent) {
+                               if (msg[0] == msg[1]) {
+                                       http_error(HE_THROW, HTTP_E_INVALID_PARAM, "Cannot prepend a message located within the same message chain");
+                                       return;
+                               }
+                       }
+               }
+               
                http_message_object_prepend_ex(getThis(), prepend, top);
        }
 }
index 84a78d8a9c0fbcd100ee8133f8b56c96e726354a..892f1c8dcaa3145e3a49a3a52a568347ca3e516b 100644 (file)
@@ -47,6 +47,7 @@ HttpResponse
  <license>BSD, revised</license>
  <notes><![CDATA[
 - Improved performance of the message and header parser
+- Disallow $HttpMessage->prepend($HttpMessage) causing infinite recursion
 * Fixed internal http_parse_headers() always returning success
 * Fixed missing "parentMessage" entry in print_r($HttpMessageObject)
 ]]></notes>