Ruslan Osmanov avatar Ruslan Osmanov committed 466c495

Fix: uninitialized socket caused segmentation fault in EventBufferEvent methods

Comments (0)

Files changed (3)

classes/buffer_event.c

 
 /* {{{ Private */
 
+#define _ret_if_invalid_bevent_ptr(bev)             \
+{                                                   \
+    if (!bev->bevent) {                             \
+        php_error_docref(NULL TSRMLS_CC, E_WARNING, \
+                "Buffer Event is not initialized"); \
+    }                                               \
+}
+
 /* {{{ bevent_rw_cb
  * Is called from the bufferevent read and write callbacks */
 static zend_always_inline void bevent_rw_cb(struct bufferevent *bevent, php_event_bevent_t *bev, zend_fcall_info *pfci, zend_fcall_info_cache *pfcc)
 
 	PHP_EVENT_FETCH_BEVENT(bev, zbevent);
 
+	_ret_if_invalid_bevent_ptr(bev);
+
 	bufferevent_setwatermark(bev->bevent, events, (size_t) lowmark, (size_t) highmark);
 }
 /* }}} */
 
 	PHP_EVENT_FETCH_BEVENT(bev, zbevent);
 
+	_ret_if_invalid_bevent_ptr(bev);
+
 	convert_to_string(zdata);
 
 	if (bufferevent_write(bev->bevent, Z_STRVAL_P(zdata), Z_STRLEN_P(zdata))) {
 	}
 
 	PHP_EVENT_FETCH_BEVENT(bev, zbevent);
+	_ret_if_invalid_bevent_ptr(bev);
+
 	PHP_EVENT_FETCH_BUFFER(b, zbuf);
 
 	if (bufferevent_write_buffer(bev->bevent, b->buf)) {
 	}
 
 	PHP_EVENT_FETCH_BEVENT(bev, zbevent);
+	_ret_if_invalid_bevent_ptr(bev);
 
 	data = safe_emalloc(size, sizeof(char), 1);
 
 	}
 
 	PHP_EVENT_FETCH_BEVENT(bev, zbevent);
+	_ret_if_invalid_bevent_ptr(bev);
+
 	PHP_EVENT_FETCH_BUFFER(b, zbuf);
 
 	if (bufferevent_read_buffer(bev->bevent, b->buf)) {
 	}
 
 	PHP_EVENT_FETCH_BEVENT(bev, zbevent);
+	_ret_if_invalid_bevent_ptr(bev);
 
 	if (bufferevent_priority_set(bev->bevent, priority)) {
 		RETURN_FALSE;
 	}
 
 	PHP_EVENT_FETCH_BEVENT(bev, zbevent);
+	_ret_if_invalid_bevent_ptr(bev);
 
 	PHP_EVENT_TIMEVAL_SET(tv_read, timeout_read);
 	PHP_EVENT_TIMEVAL_SET(tv_write, timeout_write);
 
 	PHP_EVENT_FETCH_BASE(base, zbase);
 	PHP_EVENT_FETCH_BEVENT(bev_underlying, zunderlying);
+	_ret_if_invalid_bevent_ptr(bev_underlying);
+
 	PHP_EVENT_FETCH_SSL_CONTEXT(ectx, zctx);
 
 	PHP_EVENT_INIT_CLASS_OBJECT(return_value, php_event_bevent_ce);
 	}
 
 	PHP_EVENT_FETCH_BEVENT(bev, zbevent);
+	_ret_if_invalid_bevent_ptr(bev);
 
 	e = bufferevent_get_openssl_error(bev->bevent);
 	if (e) {
 	}
 
 	PHP_EVENT_FETCH_BEVENT(bev, zbevent);
+	_ret_if_invalid_bevent_ptr(bev);
 
 	bufferevent_ssl_renegotiate(bev->bevent);
 }
     <email>osmanov@php.net</email>
     <active>yes</active>
   </lead>
-  <date>2013-03-13</date>
+  <date>2013-03-15</date>
   <!--{{{ Current version -->
   <version>
-    <release>1.4.0</release>
+    <release>1.4.1</release>
     <api>1.4.0</api>
   </version>
   <stability>
   </stability>
   <license uri="http://www.php.net/license">PHP</license>
   <notes><![CDATA[
-  Add: HTTP server support:
-    * EventHttp methods: setMaxBodySize, setMaxHeadersSize, setTimeout,
-      addServerAlias, removeServerAlias setCallback, setDefaultCallback,
-      setAllowedMethods, setMaxBodySize, setMaxHeadersSize, setTimeout,
-      addServerAlias, removeServerAlias;
-    * EventHttpRequest class, callback and custom data can be bound to the
-      request for future use with EventHttpConnection
-    * New EventHttpConnection::makeRequest method allows to make custom HTTP
-      requests by means of EventHttpRequest class
-  Change: make EventDnsBase parameter optional in EventHttpConnection::__construct
-  Fix: classes/buffer_event.c: possible memory access violation in bufferevent callback
-  Fix: turn off buggy libevent thread lock debugging when built with --enable-event-debug
+  Fix: uninitialized socket caused segmentation fault in EventBufferEvent methods
   ]]></notes>
   <!--}}}-->
   <!--{{{ Contents -->
   </extsrcrelease>
   <!--{{{ changelog-->
   <changelog>
+    <release>
+      <!--{{{ 1.4.1-beta -->
+      <version>
+        <release>1.4.1</release>
+        <api>1.4.0</api>
+      </version>
+      <stability>
+        <release>beta</release>
+        <api>beta</api>
+      </stability>
+      <license uri="http://www.php.net/license">PHP</license>
+      <notes><![CDATA[
+        Fix: uninitialized socket caused segmentation fault in EventBufferEvent methods
+        ]]></notes>
+      <!--}}}-->
+    </release>
     <!--{{{ 1.4.0-beta  -->
     <release>
       <version>
 #ifndef PHP_EVENT_H
 #define PHP_EVENT_H
 
-#define PHP_EVENT_VERSION "1.4.0-beta"
+#define PHP_EVENT_VERSION "1.4.1-beta"
 
 
 extern zend_module_entry event_module_entry;
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.