Skip to content

Commit 99ba7ba

Browse files
committed
Automatically add entropy from user opcode handlers
1 parent 2e07b63 commit 99ba7ba

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

Zend/zend_execute.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
#include "zend_inheritance.h"
4141
#include "zend_type_info.h"
4242
#include "zend_smart_str.h"
43-
#include "zend_system_id.h"
4443

4544
/* Virtual current working directory support */
4645
#include "zend_virtual_cwd.h"
@@ -4751,7 +4750,7 @@ static zend_always_inline zend_execute_data *_zend_vm_stack_push_call_frame(uint
47514750

47524751
#include "zend_vm_execute.h"
47534752

4754-
ZEND_API int zend_set_user_opcode_handler(zend_uchar opcode, user_opcode_handler_t handler, const char *module_name)
4753+
ZEND_API int zend_set_user_opcode_handler(zend_uchar opcode, user_opcode_handler_t handler)
47554754
{
47564755
if (opcode != ZEND_USER_OPCODE) {
47574756
if (handler == NULL) {
@@ -4761,7 +4760,6 @@ ZEND_API int zend_set_user_opcode_handler(zend_uchar opcode, user_opcode_handler
47614760
zend_user_opcodes[opcode] = ZEND_USER_OPCODE;
47624761
}
47634762
zend_user_opcode_handlers[opcode] = handler;
4764-
zend_add_system_entropy(module_name, "zend_set_user_opcode_handler", &opcode, sizeof(zend_uchar));
47654763
return SUCCESS;
47664764
}
47674765
return FAILURE;

Zend/zend_execute.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ ZEND_API zval* zend_get_compiled_variable_value(const zend_execute_data *execute
339339

340340
#define ZEND_USER_OPCODE_DISPATCH_TO 0x100 /* call original handler of returned opcode */
341341

342-
ZEND_API int zend_set_user_opcode_handler(zend_uchar opcode, user_opcode_handler_t handler, const char *module_name);
342+
ZEND_API int zend_set_user_opcode_handler(zend_uchar opcode, user_opcode_handler_t handler);
343343
ZEND_API user_opcode_handler_t zend_get_user_opcode_handler(zend_uchar opcode);
344344

345345
ZEND_API zval *zend_get_zval_ptr(const zend_op *opline, int op_type, const znode_op *node, const zend_execute_data *execute_data);

Zend/zend_system_id.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ void zend_startup_system_id(void)
6363
void zend_finalize_system_id(void)
6464
{
6565
unsigned char digest[16];
66-
zend_long hooks = 0;
66+
zend_uchar hooks = 0;
67+
int16_t i = 0;
6768

6869
if (zend_ast_process) {
6970
hooks |= ZEND_HOOK_AST_PROCESS;
@@ -77,7 +78,13 @@ void zend_finalize_system_id(void)
7778
if (zend_execute_internal) {
7879
hooks |= ZEND_HOOK_EXECUTE_INTERNAL;
7980
}
80-
PHP_MD5Update(&context, &hooks, sizeof(zend_long));
81+
PHP_MD5Update(&context, &hooks, sizeof(zend_uchar));
82+
83+
for (; i < 256; i++) {
84+
if (zend_get_user_opcode_handler((zend_uchar) i) != NULL) {
85+
PHP_MD5Update(&context, &i, sizeof(int16_t));
86+
}
87+
}
8188

8289
PHP_MD5Final(digest, &context);
8390
php_hash_bin2hex(zend_system_id, digest, sizeof digest);

0 commit comments

Comments
 (0)