[thrift] Error checking for T_OBJECT serialization
Summary: Avoid segfaulting via calling zend_fetch_class_entry on something
that might not actually be an object; throw an exception instead.
Reviewed by: shire
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665581 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/php/src/ext/thrift_protocol/php_thrift_protocol.cpp b/lib/php/src/ext/thrift_protocol/php_thrift_protocol.cpp
index 7a40201..86e8921 100644
--- a/lib/php/src/ext/thrift_protocol/php_thrift_protocol.cpp
+++ b/lib/php/src/ext/thrift_protocol/php_thrift_protocol.cpp
@@ -681,6 +681,9 @@
return;
case T_STRUCT: {
TSRMLS_FETCH();
+ if (Z_TYPE_PP(value) != IS_OBJECT) {
+ throw_tprotocolexception("Attempt to send non-object type as a T_STRUCT", INVALID_DATA);
+ }
zval* spec = zend_read_static_property(zend_get_class_entry(*value TSRMLS_CC), "_TSPEC", 6, false TSRMLS_CC);
binary_serialize_spec(*value, transport, Z_ARRVAL_P(spec));
} return;