Commits

Ruslan Osmanov committed b955c16

Fix: missing checks for evhttp_request_get_connection return value

Comments (0)

Files changed (1)

classes/http_request.c

 }
 /* }}} */
 
-
 /* {{{ proto EventBufferEvent EventHttpRequest::getEventBufferEvent(void);
- * Returns EventBufferEvent object. */
+ * Returns EventBufferEvent object on success, otherwise &null. */
 PHP_METHOD(EventHttpRequest, getEventBufferEvent)
 {
 	php_event_http_req_t     *http_req;
 
 	_check_http_req_ptr(http_req);
 
+	conn = evhttp_request_get_connection(http_req->ptr);
+	if (conn == NULL) {
+		RETURN_NULL();
+	}
+
 	PHP_EVENT_INIT_CLASS_OBJECT(return_value, php_event_bevent_ce);
 	PHP_EVENT_FETCH_BEVENT(bev, return_value);
-	conn = evhttp_request_get_connection(http_req->ptr);
+
 	bev->bevent = evhttp_connection_get_bufferevent(conn);
 	bev->self = return_value;
 	Z_ADDREF_P(return_value);
 
 	_check_http_req_ptr(http_req);
 
+	conn = evhttp_request_get_connection(http_req->ptr);
+	if (conn == NULL) {
+		RETURN_NULL();
+	}
+
 	PHP_EVENT_INIT_CLASS_OBJECT(return_value, php_event_http_conn_ce);
 	PHP_EVENT_FETCH_HTTP_CONN(evcon, return_value);
-	conn = evhttp_request_get_connection(http_req->ptr);
+
 	evcon->conn = conn;
 	evcon->base = NULL;
 	evcon->dns_base = NULL;
 }
 /* }}} */
 
-
-
 /* {{{ proto void EventHttpRequest::sendError(int error[, string reason = NULL]);
  * Send an HTML error message to the client.
  */