Skip to content

Commit

Permalink
Fixed hash recursive detecting
Browse files Browse the repository at this point in the history
  • Loading branch information
laruence committed Dec 21, 2018
1 parent ad31d5f commit f588c88
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
1 change: 0 additions & 1 deletion config.m4
@@ -1,4 +1,3 @@
dnl $Id: config.m4 321796 2012-01-05 17:23:48Z laruence $
PHP_ARG_WITH(lua, for lua support,
[ --with-lua=[DIR] Include php lua support])
PHP_ARG_WITH(lua-version, to specify a custom lua version, [ --with-lua-version=[VERSION]] Use the specified lua version.)
Expand Down
36 changes: 31 additions & 5 deletions lua.c
Expand Up @@ -430,13 +430,29 @@ int php_lua_send_zval_to_lua(lua_State *L, zval *val) /* {{{ */ {
zval zkey;

HashTable *ht = HASH_OF(val);
if (ZEND_HASH_APPLY_PROTECTION(ht)) {
ZEND_HASH_INC_APPLY_COUNT(ht);
if (ZEND_HASH_GET_APPLY_COUNT(ht) > 1) {
if (
#if PHP_VERSION_ID < 70300
ZEND_HASH_APPLY_PROTECTION(ht)
#else
!(GC_FLAGS(ht) & GC_IMMUTABLE)
#endif
) {
if (
#if PHP_VERSION_ID < 70300
ZEND_HASH_GET_APPLY_COUNT(ht)
#else
GC_IS_RECURSIVE(ht)
#endif
) {

php_error_docref(NULL, E_ERROR, "recursion found");
ZEND_HASH_DEC_APPLY_COUNT(ht);
break;
}
#if PHP_VERSION_ID < 70300
ZEND_HASH_INC_APPLY_COUNT(ht);
#else
GC_PROTECT_RECURSION(ht);
#endif
}

lua_newtable(L);
Expand All @@ -452,8 +468,18 @@ int php_lua_send_zval_to_lua(lua_State *L, zval *val) /* {{{ */ {
lua_settable(L, -3);
} ZEND_HASH_FOREACH_END();

if (ZEND_HASH_APPLY_PROTECTION(ht)) {
if (
#if PHP_VERSION_ID < 70300
ZEND_HASH_APPLY_PROTECTION(ht)
#else
!(GC_FLAGS(ht) & GC_IMMUTABLE)
#endif
) {
#if PHP_VERSION_ID < 70300
ZEND_HASH_DEC_APPLY_COUNT(ht);
#else
GC_UNPROTECT_RECURSION(ht);
#endif
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion php_lua.h
Expand Up @@ -48,7 +48,7 @@ extern zend_module_entry lua_module_entry;
#define LUA_G(v) (lua_globals.v)
#endif

#define PHP_LUA_VERSION "2.0.6-dev"
#define PHP_LUA_VERSION "2.0.6"

struct _php_lua_object {
lua_State *L;
Expand Down

0 comments on commit f588c88

Please sign in to comment.