Ruslan Osmanov avatar 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.
  */
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.