https://www.mediawiki.org/wiki/Special:Code/MediaWiki/113802

Revision: 113802
Author:   tstarling
Date:     2012-03-14 09:08:09 +0000 (Wed, 14 Mar 2012)
Log Message:
-----------
Fix exception handling in LuaSandbox, per Victor's fixme comment in Engine.php. 
Avoid a segfault by only trying to destroy the retval if it is not null, and 
kill the Lua code with an error when PHP throws an exception.

Modified Paths:
--------------
    trunk/php/luasandbox/luasandbox.c

Modified: trunk/php/luasandbox/luasandbox.c
===================================================================
--- trunk/php/luasandbox/luasandbox.c   2012-03-14 09:07:01 UTC (rev 113801)
+++ trunk/php/luasandbox/luasandbox.c   2012-03-14 09:08:09 UTC (rev 113802)
@@ -783,7 +783,9 @@
 {
        const char * errorMsg = lua_tostring(L, -1);
        lua_pop(L, 1);
-       zend_throw_exception(luasandboxerror_ce, (char*)errorMsg, status);
+       if (!EG(exception)) {
+               zend_throw_exception(luasandboxerror_ce, (char*)errorMsg, 
status);
+       }
 }
 /* }}} */
 
@@ -1613,17 +1615,22 @@
                // Push the return value back to Lua
                luasandbox_push_zval(L, *fci.retval_ptr_ptr);
                num_results = 1;
+               zval_ptr_dtor(&retval_ptr);
        }
 
-       // Free the zvals
+       // Free the argument zvals
        for (i = 0; i < top; i++) {
                zval_ptr_dtor(&(pointers[i]));
        }
-       zval_ptr_dtor(&retval_ptr);
 
        // Free the pointer arrays
        efree(temp);
        luasandbox_leave_php(L, intern);
+
+       // If an exception occurred, convert it to a Lua error (just to unwind 
the stack)
+       if (EG(exception)) {
+               luaL_error(L, "[exception]");
+       }
        return num_results;
 }
 /* }}} */


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to