diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/snuffleupagus.c | 2 | ||||
| -rw-r--r-- | src/sp_execute.c | 8 | ||||
| -rw-r--r-- | src/sp_sloppy.c | 21 | ||||
| -rw-r--r-- | src/tests/global_strict/global_strict_issue432.phpt | 21 | ||||
| -rw-r--r-- | src/tests/sloppy_comparison/sloppy_comparison.phpt | 2 | ||||
| -rw-r--r-- | src/tests/sloppy_comparison/sloppy_comparison_array.phpt | 2 | ||||
| -rw-r--r-- | src/tests/sloppy_comparison/sloppy_comparison_array_keys.phpt | 4 | ||||
| -rw-r--r-- | src/tests/sloppy_comparison/sloppy_comparison_array_search.phpt | 4 | ||||
| -rw-r--r-- | src/tests/sloppy_comparison/sloppy_comparison_disable.phpt | 19 |
9 files changed, 62 insertions, 21 deletions
diff --git a/src/snuffleupagus.c b/src/snuffleupagus.c index 30f6b3d..be6240e 100644 --- a/src/snuffleupagus.c +++ b/src/snuffleupagus.c | |||
| @@ -21,7 +21,7 @@ ZEND_DLEXPORT int sp_zend_startup(zend_extension *extension) { | |||
| 21 | 21 | ||
| 22 | static inline void sp_op_array_handler(zend_op_array *const op) { | 22 | static inline void sp_op_array_handler(zend_op_array *const op) { |
| 23 | // We need a filename, and strict mode not already enabled on this op | 23 | // We need a filename, and strict mode not already enabled on this op |
| 24 | if (NULL == op->filename || op->fn_flags & ZEND_ACC_STRICT_TYPES) { | 24 | if (NULL == op->filename) { |
| 25 | return; | 25 | return; |
| 26 | } else { | 26 | } else { |
| 27 | if (SPCFG(global_strict).enable) { | 27 | if (SPCFG(global_strict).enable) { |
diff --git a/src/sp_execute.c b/src/sp_execute.c index b4e5c6c..5c0c939 100644 --- a/src/sp_execute.c +++ b/src/sp_execute.c | |||
| @@ -353,14 +353,18 @@ ZEND_API zend_op_array* sp_compile_string(zval* source_string, char* filename) { | |||
| 353 | // TODO(jvoisin) handle recursive calls to `eval` | 353 | // TODO(jvoisin) handle recursive calls to `eval` |
| 354 | SPG(eval_source_string) = source_string; | 354 | SPG(eval_source_string) = source_string; |
| 355 | zend_op_array* opline = orig_zend_compile_string(source_string, filename); | 355 | zend_op_array* opline = orig_zend_compile_string(source_string, filename); |
| 356 | sp_sloppy_modify_opcode(opline); | 356 | if (SPCFG(sloppy).enable) { |
| 357 | sp_sloppy_modify_opcode(opline); | ||
| 358 | } | ||
| 357 | return opline; | 359 | return opline; |
| 358 | } | 360 | } |
| 359 | 361 | ||
| 360 | ZEND_API zend_op_array* sp_compile_file(zend_file_handle* file_handle, | 362 | ZEND_API zend_op_array* sp_compile_file(zend_file_handle* file_handle, |
| 361 | int type) { | 363 | int type) { |
| 362 | zend_op_array* opline = orig_zend_compile_file(file_handle, type); | 364 | zend_op_array* opline = orig_zend_compile_file(file_handle, type); |
| 363 | sp_sloppy_modify_opcode(opline); | 365 | if (SPCFG(sloppy).enable) { |
| 366 | sp_sloppy_modify_opcode(opline); | ||
| 367 | } | ||
| 364 | return opline; | 368 | return opline; |
| 365 | } | 369 | } |
| 366 | 370 | ||
diff --git a/src/sp_sloppy.c b/src/sp_sloppy.c index 2c6ef6a..4c97d0e 100644 --- a/src/sp_sloppy.c +++ b/src/sp_sloppy.c | |||
| @@ -1,16 +1,17 @@ | |||
| 1 | #include "php_snuffleupagus.h" | 1 | #include "php_snuffleupagus.h" |
| 2 | 2 | ||
| 3 | void sp_sloppy_modify_opcode(zend_op_array* opline) { | 3 | void sp_sloppy_modify_opcode(zend_op_array* opline) { |
| 4 | if (NULL != opline) { | 4 | if (NULL == opline) { |
| 5 | for (size_t i = 0; i < opline->last; i++) { | 5 | return; |
| 6 | zend_op* orig_opline = &(opline->opcodes[i]); | 6 | } |
| 7 | if (orig_opline->opcode == ZEND_IS_EQUAL) { | 7 | for (size_t i = 0; i < opline->last; i++) { |
| 8 | orig_opline->opcode = ZEND_IS_IDENTICAL; | 8 | zend_op* orig_opline = &(opline->opcodes[i]); |
| 9 | zend_vm_set_opcode_handler(orig_opline); | 9 | if (orig_opline->opcode == ZEND_IS_EQUAL) { |
| 10 | } else if (orig_opline->opcode == ZEND_IS_NOT_EQUAL) { | 10 | orig_opline->opcode = ZEND_IS_IDENTICAL; |
| 11 | orig_opline->opcode = ZEND_IS_NOT_IDENTICAL; | 11 | zend_vm_set_opcode_handler(orig_opline); |
| 12 | zend_vm_set_opcode_handler(orig_opline); | 12 | } else if (orig_opline->opcode == ZEND_IS_NOT_EQUAL) { |
| 13 | } | 13 | orig_opline->opcode = ZEND_IS_NOT_IDENTICAL; |
| 14 | zend_vm_set_opcode_handler(orig_opline); | ||
| 14 | } | 15 | } |
| 15 | } | 16 | } |
| 16 | } | 17 | } |
diff --git a/src/tests/global_strict/global_strict_issue432.phpt b/src/tests/global_strict/global_strict_issue432.phpt new file mode 100644 index 0000000..008529e --- /dev/null +++ b/src/tests/global_strict/global_strict_issue432.phpt | |||
| @@ -0,0 +1,21 @@ | |||
| 1 | --TEST-- | ||
| 2 | Global strict mode, for issue #432 | ||
| 3 | --SKIPIF-- | ||
| 4 | <?php if (!extension_loaded("snuffleupagus")) print "skip"; ?> | ||
| 5 | --INI-- | ||
| 6 | sp.configuration_file={PWD}/config/global_strict_disabled.ini | ||
| 7 | --FILE-- | ||
| 8 | <?php | ||
| 9 | $filename = '/tmp/test.txt'; | ||
| 10 | file_put_contents($filename, '0'); | ||
| 11 | $var = file_get_contents($filename); | ||
| 12 | if ($var == "0") { | ||
| 13 | print("WIN"); | ||
| 14 | } | ||
| 15 | if ($var == 0) { | ||
| 16 | print("WIN"); | ||
| 17 | } | ||
| 18 | unlink($filename); | ||
| 19 | ?> | ||
| 20 | --EXPECT-- | ||
| 21 | WINWIN | ||
diff --git a/src/tests/sloppy_comparison/sloppy_comparison.phpt b/src/tests/sloppy_comparison/sloppy_comparison.phpt index da28e3d..cf91f15 100644 --- a/src/tests/sloppy_comparison/sloppy_comparison.phpt +++ b/src/tests/sloppy_comparison/sloppy_comparison.phpt | |||
| @@ -12,7 +12,7 @@ if ($qwe == 0) { | |||
| 12 | } | 12 | } |
| 13 | $qwe = "0e123"; | 13 | $qwe = "0e123"; |
| 14 | if ("0e432" == $qwe) { | 14 | if ("0e432" == $qwe) { |
| 15 | echo "failed"; | 15 | echo "failed_power"; |
| 16 | } | 16 | } |
| 17 | $qwe = []; | 17 | $qwe = []; |
| 18 | $test = false; | 18 | $test = false; |
diff --git a/src/tests/sloppy_comparison/sloppy_comparison_array.phpt b/src/tests/sloppy_comparison/sloppy_comparison_array.phpt index 79f9ed6..1316663 100644 --- a/src/tests/sloppy_comparison/sloppy_comparison_array.phpt +++ b/src/tests/sloppy_comparison/sloppy_comparison_array.phpt | |||
| @@ -8,7 +8,7 @@ sp.configuration_file={PWD}/config/sloppy_comparison.ini | |||
| 8 | <?php | 8 | <?php |
| 9 | $qwe = array(rand(1,2), "qwe"); | 9 | $qwe = array(rand(1,2), "qwe"); |
| 10 | var_dump(in_array(0, $qwe)); | 10 | var_dump(in_array(0, $qwe)); |
| 11 | var_dump(in_array(0, $qwe, 0)); | 11 | var_dump(in_array(0, $qwe, false)); |
| 12 | ?> | 12 | ?> |
| 13 | --EXPECT-- | 13 | --EXPECT-- |
| 14 | bool(false) | 14 | bool(false) |
diff --git a/src/tests/sloppy_comparison/sloppy_comparison_array_keys.phpt b/src/tests/sloppy_comparison/sloppy_comparison_array_keys.phpt index 934f3ba..25e89e8 100644 --- a/src/tests/sloppy_comparison/sloppy_comparison_array_keys.phpt +++ b/src/tests/sloppy_comparison/sloppy_comparison_array_keys.phpt | |||
| @@ -8,8 +8,8 @@ sp.configuration_file={PWD}/config/sloppy_comparison.ini | |||
| 8 | <?php | 8 | <?php |
| 9 | $qwe = array(rand(1,2), "qwe"); | 9 | $qwe = array(rand(1,2), "qwe"); |
| 10 | var_dump(array_keys($qwe, 0)); | 10 | var_dump(array_keys($qwe, 0)); |
| 11 | var_dump(array_keys($qwe, 0, 0)); | 11 | var_dump(array_keys($qwe, 0, FALSE)); |
| 12 | var_dump(array_keys($qwe, 0, 1)); | 12 | var_dump(array_keys($qwe, 0, TRUE)); |
| 13 | 13 | ||
| 14 | $toto = [ | 14 | $toto = [ |
| 15 | "toto" => 1, | 15 | "toto" => 1, |
diff --git a/src/tests/sloppy_comparison/sloppy_comparison_array_search.phpt b/src/tests/sloppy_comparison/sloppy_comparison_array_search.phpt index 60d11d1..ac3f10f 100644 --- a/src/tests/sloppy_comparison/sloppy_comparison_array_search.phpt +++ b/src/tests/sloppy_comparison/sloppy_comparison_array_search.phpt | |||
| @@ -8,8 +8,8 @@ sp.configuration_file={PWD}/config/sloppy_comparison.ini | |||
| 8 | <?php | 8 | <?php |
| 9 | $qwe = array(rand(1,2), "qwe"); | 9 | $qwe = array(rand(1,2), "qwe"); |
| 10 | var_dump(array_search(0, $qwe)); | 10 | var_dump(array_search(0, $qwe)); |
| 11 | var_dump(array_search(0, $qwe, 0)); | 11 | var_dump(array_search(0, $qwe, FALSE)); |
| 12 | var_dump(array_search(0, $qwe, 1)); | 12 | var_dump(array_search(0, $qwe, TRUE)); |
| 13 | ?> | 13 | ?> |
| 14 | --EXPECT-- | 14 | --EXPECT-- |
| 15 | bool(false) | 15 | bool(false) |
diff --git a/src/tests/sloppy_comparison/sloppy_comparison_disable.phpt b/src/tests/sloppy_comparison/sloppy_comparison_disable.phpt index cdcd9a8..be615f5 100644 --- a/src/tests/sloppy_comparison/sloppy_comparison_disable.phpt +++ b/src/tests/sloppy_comparison/sloppy_comparison_disable.phpt | |||
| @@ -9,8 +9,23 @@ sp.allow_broken_configuration=On | |||
| 9 | <?php | 9 | <?php |
| 10 | $qwe = "abc"; | 10 | $qwe = "abc"; |
| 11 | if ($qwe == 0) { | 11 | if ($qwe == 0) { |
| 12 | echo "OK"; | 12 | echo "ONE"; |
| 13 | } | 13 | } |
| 14 | $qwe = "0e123"; | ||
| 15 | if ("0e432" == $qwe) { | ||
| 16 | echo "TWO"; | ||
| 17 | } | ||
| 18 | $qwe = []; | ||
| 19 | $test = false; | ||
| 20 | if ($test == $qwe) { | ||
| 21 | echo "THREE"; | ||
| 22 | } | ||
| 23 | eval(" | ||
| 24 | \$asd = 'qwe'; | ||
| 25 | if (\$asd == 0) { | ||
| 26 | echo 'FOUR'; | ||
| 27 | } | ||
| 28 | "); | ||
| 14 | ?> | 29 | ?> |
| 15 | --EXPECT-- | 30 | --EXPECT-- |
| 16 | OK | 31 | ONETWOTHREEFOUR |
