Skip to content

Commit d83bc0e

Browse files
committed
Fix a few things, restore checks for characters, add handlers
1 parent bc06da0 commit d83bc0e

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

Zend/zend_autoload.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ void* zend_autoload_call(zend_string *name, zend_string *lname, long type)
4242
zval dummy, ztype, zname, retval;
4343
zend_autoload_func *func_info;
4444

45+
/* Verify autoload name before passing it to __autoload() */
46+
if (strspn(name->val, "0123456789_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\177\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377\\") != name->len) {
47+
return NULL;
48+
}
49+
4550
ZVAL_UNDEF(&dummy);
4651
ZVAL_LONG(&ztype, type);
4752
ZVAL_STR(&zname, name);

Zend/zend_execute.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ ZEND_API void execute_ex(zend_execute_data *execute_data);
4242
ZEND_API void execute_internal(zend_execute_data *execute_data, zval *return_value);
4343
ZEND_API zend_class_entry *zend_lookup_class(zend_string *name);
4444
ZEND_API zend_class_entry *zend_lookup_class_ex(zend_string *name, const zval *key, int use_autoload);
45+
ZEND_API zend_function *zend_lookup_function(zend_string *name);
46+
ZEND_API zend_function *zend_lookup_function_ex(zend_string *name, const zval *key, int use_autoload);
47+
48+
#define ZEND_LOOKUP_FUNCTION_BY_NAME(name, fbc) ((fbc = (zend_function*) zend_hash_find(EG(function_table), name)) != NULL || (fbc = zend_lookup_function(name)) != NULL)
49+
4550
ZEND_API int zend_eval_string(char *str, zval *retval_ptr, char *string_name);
4651
ZEND_API int zend_eval_stringl(char *str, size_t str_len, zval *retval_ptr, char *string_name);
4752
ZEND_API int zend_eval_string_ex(char *str, zval *retval_ptr, char *string_name, int handle_exceptions);

Zend/zend_execute_API.c

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,60 @@ ZEND_API zend_class_entry *zend_lookup_class(zend_string *name) /* {{{ */
973973
}
974974
/* }}} */
975975

976+
ZEND_API zend_function *zend_lookup_function(zend_string *name) /* {{{ */
977+
{
978+
return zend_lookup_function_ex(name, NULL, 1);
979+
}
980+
/* }}} */
981+
982+
ZEND_API zend_function *zend_lookup_function_ex(zend_string *name, const zval *key, int use_autoload) /* {{{ */
983+
{
984+
zend_function *fe = NULL;
985+
zend_string *lc_name;
986+
987+
if (key) {
988+
lc_name = Z_STR_P(key);
989+
} else {
990+
if (name == NULL || !name->len) {
991+
return NULL;
992+
}
993+
994+
if (name->val[0] == '\\') {
995+
lc_name = zend_string_alloc(name->len - 1, 0);
996+
zend_str_tolower_copy(lc_name->val, name->val + 1, name->len - 1);
997+
} else {
998+
lc_name = zend_string_alloc(name->len, 0);
999+
zend_str_tolower_copy(lc_name->val, name->val, name->len);
1000+
}
1001+
}
1002+
1003+
fe = zend_hash_find_ptr(EG(function_table), lc_name);
1004+
if (fe) {
1005+
if (!key) {
1006+
zend_string_free(lc_name);
1007+
}
1008+
return fe;
1009+
}
1010+
1011+
/* The compiler is not-reentrant. Make sure we __autoload() only during run-time
1012+
* (doesn't impact functionality of __autoload()
1013+
*/
1014+
if (!use_autoload || zend_is_compiling()) {
1015+
if (!key) {
1016+
zend_string_free(lc_name);
1017+
}
1018+
return NULL;
1019+
}
1020+
1021+
fe = (zend_function*) zend_autoload_call(name, lc_name, ZEND_AUTOLOAD_FUNCTION);
1022+
1023+
if (!key) {
1024+
zend_string_free(lc_name);
1025+
}
1026+
return fe;
1027+
}
1028+
/* }}} */
1029+
9761030
ZEND_API int zend_eval_stringl(char *str, size_t str_len, zval *retval_ptr, char *string_name) /* {{{ */
9771031
{
9781032
zval pv;

0 commit comments

Comments
 (0)