Skip to content

Commit b63e4cf

Browse files
committed
Handle holes in zend_get_opcode_id()
Some opcodes may currently not be allocated.
1 parent 8869bbe commit b63e4cf

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

Zend/zend_vm_gen.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2688,7 +2688,8 @@ function gen_vm($def, $skel) {
26882688
fputs($f, "ZEND_API zend_uchar zend_get_opcode_id(const char *name, size_t length) {\n");
26892689
fputs($f, "\tzend_uchar opcode;\n");
26902690
fputs($f, "\tfor (opcode = 0; opcode < (sizeof(zend_vm_opcodes_names) / sizeof(zend_vm_opcodes_names[0])) - 1; opcode++) {\n");
2691-
fputs($f, "\t\tif (strncmp(zend_vm_opcodes_names[opcode], name, length) == 0) {\n");
2691+
fputs($f, "\t\tconst char *opcode_name = zend_vm_opcodes_names[opcode];\n");
2692+
fputs($f, "\t\tif (opcode_name && strncmp(opcode_name, name, length) == 0) {\n");
26922693
fputs($f, "\t\t\treturn opcode;\n");
26932694
fputs($f, "\t\t}\n");
26942695
fputs($f, "\t}\n");

Zend/zend_vm_opcodes.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,8 @@ ZEND_API uint32_t ZEND_FASTCALL zend_get_opcode_flags(zend_uchar opcode) {
449449
ZEND_API zend_uchar zend_get_opcode_id(const char *name, size_t length) {
450450
zend_uchar opcode;
451451
for (opcode = 0; opcode < (sizeof(zend_vm_opcodes_names) / sizeof(zend_vm_opcodes_names[0])) - 1; opcode++) {
452-
if (strncmp(zend_vm_opcodes_names[opcode], name, length) == 0) {
452+
const char *opcode_name = zend_vm_opcodes_names[opcode];
453+
if (opcode_name && strncmp(opcode_name, name, length) == 0) {
453454
return opcode;
454455
}
455456
}

0 commit comments

Comments
 (0)