Index: trunk/php/luasandbox/luasandbox.c |
— | — | @@ -46,6 +46,7 @@ |
47 | 47 | static zend_bool luasandbox_instanceof( |
48 | 48 | zend_class_entry *child_class, zend_class_entry *parent_class); |
49 | 49 | |
| 50 | +extern char luasandbox_timeout_message[]; |
50 | 51 | |
51 | 52 | zend_class_entry *luasandbox_ce; |
52 | 53 | zend_class_entry *luasandboxerror_ce; |
— | — | @@ -54,8 +55,8 @@ |
55 | 56 | zend_class_entry *luasandboxsyntaxerror_ce; |
56 | 57 | zend_class_entry *luasandboxmemoryerror_ce; |
57 | 58 | zend_class_entry *luasandboxerrorerror_ce; |
58 | | -zend_class_entry *luasandboxtimeout_ce; |
59 | | -zend_class_entry *luasandboxemergencytimeout_ce; |
| 59 | +zend_class_entry *luasandboxtimeouterror_ce; |
| 60 | +zend_class_entry *luasandboxemergencytimeouterror_ce; |
60 | 61 | zend_class_entry *luasandboxplaceholder_ce; |
61 | 62 | zend_class_entry *luasandboxfunction_ce; |
62 | 63 | |
— | — | @@ -197,12 +198,12 @@ |
198 | 199 | luasandboxerrorerror_ce = zend_register_internal_class_ex( |
199 | 200 | &ce, luasandboxfatalerror_ce, NULL TSRMLS_CC); |
200 | 201 | |
201 | | - INIT_CLASS_ENTRY(ce, "LuaSandboxTimeout", luasandbox_empty_methods); |
202 | | - luasandboxtimeout_ce = zend_register_internal_class_ex( |
| 202 | + INIT_CLASS_ENTRY(ce, "LuaSandboxTimeoutError", luasandbox_empty_methods); |
| 203 | + luasandboxtimeouterror_ce = zend_register_internal_class_ex( |
203 | 204 | &ce, luasandboxfatalerror_ce, NULL TSRMLS_CC); |
204 | 205 | |
205 | | - INIT_CLASS_ENTRY(ce, "LuaSandboxEmergencyTimeout", luasandbox_empty_methods); |
206 | | - luasandboxemergencytimeout_ce = zend_register_internal_class_ex( |
| 206 | + INIT_CLASS_ENTRY(ce, "LuaSandboxEmergencyTimeoutError", luasandbox_empty_methods); |
| 207 | + luasandboxemergencytimeouterror_ce = zend_register_internal_class_ex( |
207 | 208 | &ce, luasandboxfatalerror_ce, NULL TSRMLS_CC); |
208 | 209 | |
209 | 210 | zend_declare_class_constant_long(luasandboxerror_ce, |
— | — | @@ -551,7 +552,7 @@ |
552 | 553 | lua_close(sandbox->state); |
553 | 554 | sandbox->state = NULL; |
554 | 555 | sandbox->emergency_timed_out = 0; |
555 | | - zend_throw_exception(luasandboxemergencytimeout_ce, |
| 556 | + zend_throw_exception(luasandboxemergencytimeouterror_ce, |
556 | 557 | "The maximum execution time was exceeded " |
557 | 558 | "and the current Lua statement failed to return, leading to " |
558 | 559 | "destruction of the Lua state", LUA_ERRRUN); |
— | — | @@ -568,11 +569,21 @@ |
569 | 570 | { |
570 | 571 | const char * errorMsg = luasandbox_error_to_string(L, -1); |
571 | 572 | zend_class_entry * ce; |
572 | | - lua_pop(L, 1); |
573 | 573 | if (!EG(exception)) { |
| 574 | + if (luasandbox_is_fatal(L, -1) && !strcmp(errorMsg, luasandbox_timeout_message)) { |
| 575 | + ce = luasandboxtimeouterror_ce; |
| 576 | + } |
574 | 577 | switch (status) { |
575 | 578 | case LUA_ERRRUN: |
576 | | - ce = luasandboxruntimeerror_ce; |
| 579 | + if (luasandbox_is_fatal(L, -1)) { |
| 580 | + if (!strcmp(errorMsg, luasandbox_timeout_message)) { |
| 581 | + ce = luasandboxtimeouterror_ce; |
| 582 | + } else { |
| 583 | + ce = luasandboxfatalerror_ce; |
| 584 | + } |
| 585 | + } else { |
| 586 | + ce = luasandboxruntimeerror_ce; |
| 587 | + } |
577 | 588 | break; |
578 | 589 | case LUA_ERRSYNTAX: |
579 | 590 | ce = luasandboxsyntaxerror_ce; |
— | — | @@ -586,6 +597,7 @@ |
587 | 598 | } |
588 | 599 | zend_throw_exception(ce, (char*)errorMsg, status); |
589 | 600 | } |
| 601 | + lua_pop(L, 1); |
590 | 602 | } |
591 | 603 | /* }}} */ |
592 | 604 | |
Index: trunk/php/luasandbox/data_conversion.c |
— | — | @@ -7,6 +7,7 @@ |
8 | 8 | #include <lauxlib.h> |
9 | 9 | #include <limits.h> |
10 | 10 | #include <float.h> |
| 11 | +#include <math.h> |
11 | 12 | |
12 | 13 | #include "php.h" |
13 | 14 | #include "php_luasandbox.h" |
— | — | @@ -332,10 +333,12 @@ |
333 | 334 | const char * str; |
334 | 335 | size_t length; |
335 | 336 | zval *value; |
| 337 | + lua_Number n; |
| 338 | + int top = lua_gettop(L); |
336 | 339 | |
337 | 340 | // Normalise the input index so that we can push without invalidating it. |
338 | 341 | if (index < 0) { |
339 | | - index += lua_gettop(L) + 1; |
| 342 | + index += top + 1; |
340 | 343 | } |
341 | 344 | |
342 | 345 | lua_pushnil(L); |
— | — | @@ -343,13 +346,23 @@ |
344 | 347 | MAKE_STD_ZVAL(value); |
345 | 348 | luasandbox_lua_to_zval(value, L, -1, sandbox_zval, recursionGuard TSRMLS_CC); |
346 | 349 | |
| 350 | + if (lua_type(L, -2) == LUA_TNUMBER) { |
| 351 | + n = lua_tonumber(L, -2); |
| 352 | + if (n == floor(n)) { |
| 353 | + // Integer key |
| 354 | + zend_hash_index_update(ht, n, (void*)&value, sizeof(zval*), NULL); |
| 355 | + lua_settop(L, top + 1); |
| 356 | + continue; |
| 357 | + } |
| 358 | + } |
| 359 | + |
347 | 360 | // Make a copy of the key so that we can call lua_tolstring() which is destructive |
348 | 361 | lua_pushvalue(L, -2); |
349 | 362 | str = lua_tolstring(L, -1, &length); |
350 | 363 | zend_hash_update(ht, str, length + 1, (void*)&value, sizeof(zval*), NULL); |
351 | 364 | |
352 | | - // Delete the copy and the value |
353 | | - lua_pop(L, 2); |
| 365 | + // Pop temporary values off the stack |
| 366 | + lua_settop(L, top + 1); |
354 | 367 | } |
355 | 368 | } |
356 | 369 | /* }}} */ |