]> granicus.if.org Git - php/commitdiff
Don't silence fatal errors with @
authorNikita Popov <nikita.ppv@gmail.com>
Mon, 26 Nov 2018 20:20:03 +0000 (21:20 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Mon, 11 Feb 2019 15:17:55 +0000 (16:17 +0100)
15 files changed:
UPGRADING
Zend/tests/bug34786.phpt
Zend/zend_errors.h
Zend/zend_execute.c
Zend/zend_vm_def.h
Zend/zend_vm_execute.h
ext/mbstring/tests/mb_substitute_character_variation1.phpt
ext/spl/tests/class_implements_variation1.phpt
ext/spl/tests/class_uses_variation1.phpt
ext/standard/tests/array/array_multisort_variation1.phpt
ext/standard/tests/array/array_multisort_variation2.phpt
ext/standard/tests/array/array_multisort_variation3.phpt
ext/standard/tests/file/file_put_contents_variation2.phpt
ext/standard/tests/file/file_put_contents_variation3.phpt
ext/standard/tests/general_functions/intval_variation1.phpt

index 1ca0d2af4f2cf038b6899d2d7f1a72e93cf53658..32c9f847d1f5b182cc33a51aa219f929fadaa73e 100644 (file)
--- a/UPGRADING
+++ b/UPGRADING
@@ -42,6 +42,30 @@ PHP 8.0 UPGRADE NOTES
   . Any array that has a number n as its first numeric key will use n+1 for
     its next implicit key. Even if n is negative.
     RFC: https://wiki.php.net/rfc/negative_array_index
+  . The @ operator will no longer silence fatal errors (E_ERROR, E_CORE_ERROR,
+    E_COMPILE_ERROR, E_USER_ERROR, E_RECOVERABLE_ERROR, E_PARSE). Error handlers
+    that expect error_reporting to be 0 when @ is used, should be adjusted to
+    use a mask check instead:
+
+        // Replace
+        function my_error_handler($err_no, $err_msg, $filename, $linenum) {
+            if (error_reporting() == 0)
+                return; // Silenced
+            }
+            // ...
+        }
+
+        // With
+        function my_error_handler($err_no, $err_msg, $filename, $linenum) {
+            if (error_reporting() & $err_no)
+                return; // Silenced
+            }
+            // ...
+        }
+
+    Additionally, care should be taken that error messages are not displayed in
+    production environments, which can result in information leaks. Please
+    ensure that display_errors=Off is used in conjunction with error logging.
 
 - Date:
   . mktime() and gmmktime() now require at least one argument. time() can be
index 18642848d8424e160494bccb9f11bea578afae78..ef0627633fcdabb0155882efd86e33ee53c7b756 100644 (file)
@@ -10,13 +10,13 @@ function bar() {
 echo "bar: ".error_reporting()."\n";
 }
 
-error_reporting(1);
+error_reporting(E_WARNING);
 echo "before: ".error_reporting()."\n";
 @foo(1,@bar(),3);
 echo "after: ".error_reporting()."\n";
 ?>
 --EXPECT--
-before: 1
+before: 2
 bar: 0
 foo: 0
-after: 1
+after: 2
index 441458c033afe382b5bb3a37ae73d00ddaa0e13f..6fda0f843e3bd24919d341ed750cd296743111d9 100644 (file)
@@ -39,4 +39,9 @@
 #define E_ALL (E_ERROR | E_WARNING | E_PARSE | E_NOTICE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING | E_USER_ERROR | E_USER_WARNING | E_USER_NOTICE | E_RECOVERABLE_ERROR | E_DEPRECATED | E_USER_DEPRECATED | E_STRICT)
 #define E_CORE (E_CORE_ERROR | E_CORE_WARNING)
 
+/* Fatal errors that are ignored by the silence operator */
+#define E_FATAL_ERRORS (E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR | E_RECOVERABLE_ERROR | E_PARSE)
+
+#define E_HAS_ONLY_FATAL_ERRORS(mask) !((mask) & ~E_FATAL_ERRORS)
+
 #endif /* ZEND_ERRORS_H */
index d90e9ab07552f2ca3e8c49e9fbab3ef4add90941..a2f52069829c26db988f49c201f119b8126dfeb8 100644 (file)
@@ -3757,7 +3757,8 @@ static void cleanup_live_vars(zend_execute_data *execute_data, uint32_t op_num,
                                        }
                                } else if (kind == ZEND_LIVE_SILENCE) {
                                        /* restore previous error_reporting value */
-                                       if (!EG(error_reporting) && Z_LVAL_P(var) != 0) {
+                                       if (E_HAS_ONLY_FATAL_ERRORS(EG(error_reporting))
+                                                       && !E_HAS_ONLY_FATAL_ERRORS(Z_LVAL_P(var))) {
                                                EG(error_reporting) = Z_LVAL_P(var);
                                        }
                                }
index 21ec5ad7d11a6b3593a66be76fe88c0c798429f2..40228ecc3233da843ecc22567422426a03fa86ad 100644 (file)
@@ -6755,9 +6755,10 @@ ZEND_VM_HANDLER(57, ZEND_BEGIN_SILENCE, ANY, ANY)
 
        ZVAL_LONG(EX_VAR(opline->result.var), EG(error_reporting));
 
-       if (EG(error_reporting)) {
+       if (!E_HAS_ONLY_FATAL_ERRORS(EG(error_reporting))) {
                do {
-                       EG(error_reporting) = 0;
+                       /* Do not silence fatal errors */
+                       EG(error_reporting) &= E_FATAL_ERRORS;
                        if (!EG(error_reporting_ini_entry)) {
                                zval *zv = zend_hash_find_ex(EG(ini_directives), ZSTR_KNOWN(ZEND_STR_ERROR_REPORTING), 1);
                                if (zv) {
@@ -6786,7 +6787,8 @@ ZEND_VM_HANDLER(58, ZEND_END_SILENCE, TMP, ANY)
 {
        USE_OPLINE
 
-       if (!EG(error_reporting) && Z_LVAL_P(EX_VAR(opline->op1.var)) != 0) {
+       if (E_HAS_ONLY_FATAL_ERRORS(EG(error_reporting))
+                       && !E_HAS_ONLY_FATAL_ERRORS(Z_LVAL_P(EX_VAR(opline->op1.var)))) {
                EG(error_reporting) = Z_LVAL_P(EX_VAR(opline->op1.var));
        }
        ZEND_VM_NEXT_OPCODE();
index d9cac78025b78ada13331cb53a7e534ab1b90b6c..9a0fc62663ce8d0e75cb0e7bbc373d33bf93a266 100644 (file)
@@ -1493,9 +1493,10 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_BEGIN_SILENCE_SPEC_HANDLER(ZEN
 
        ZVAL_LONG(EX_VAR(opline->result.var), EG(error_reporting));
 
-       if (EG(error_reporting)) {
+       if (!E_HAS_ONLY_FATAL_ERRORS(EG(error_reporting))) {
                do {
-                       EG(error_reporting) = 0;
+                       /* Do not silence fatal errors */
+                       EG(error_reporting) &= E_FATAL_ERRORS;
                        if (!EG(error_reporting_ini_entry)) {
                                zval *zv = zend_hash_find_ex(EG(ini_directives), ZSTR_KNOWN(ZEND_STR_ERROR_REPORTING), 1);
                                if (zv) {
@@ -19620,7 +19621,8 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_END_SILENCE_SPEC_TMP_HANDLER(Z
 {
        USE_OPLINE
 
-       if (!EG(error_reporting) && Z_LVAL_P(EX_VAR(opline->op1.var)) != 0) {
+       if (E_HAS_ONLY_FATAL_ERRORS(EG(error_reporting))
+                       && !E_HAS_ONLY_FATAL_ERRORS(Z_LVAL_P(EX_VAR(opline->op1.var)))) {
                EG(error_reporting) = Z_LVAL_P(EX_VAR(opline->op1.var));
        }
        ZEND_VM_NEXT_OPCODE();
index 68e1ad7ca89ba1ee28c333f47ba171ed5e82143c..69912eca5087675be133bd72919098dc197ff264 100644 (file)
@@ -17,7 +17,7 @@ echo "*** Testing mb_substitute_character() : usage variation ***\n";
 
 // Define error handler
 function test_error_handler($err_no, $err_msg, $filename, $linenum) {
-       if (error_reporting() != 0) {
+       if (error_reporting() & $err_no) {
                // report non-silenced errors
                echo "Error: $err_no - $err_msg, $filename($linenum)\n";
        }
index 8b122a79f1525da4d32a712ff1cfeedf1d50838d..4c70f2b412fb165f5704751792aa6f06a38e5222 100644 (file)
@@ -13,7 +13,7 @@ echo "*** Testing class_implements() : variation ***\n";
 
 // Define error handler
 function test_error_handler($err_no, $err_msg, $filename, $linenum) {
-       if (error_reporting() != 0) {
+       if (error_reporting() & $err_no) {
                // report non-silenced errors
                echo "Error: $err_no - $err_msg, $filename($linenum)\n";
        }
index fbf476b493642c7a1704f9d22ff59198354ab9f9..538c9257e7b3ebdbd8a2dcc08f3927f3bc258ff1 100644 (file)
@@ -13,7 +13,7 @@ echo "*** Testing class_uses() : variation ***\n";
 
 // Define error handler
 function test_error_handler($err_no, $err_msg, $filename, $linenum) {
-       if (error_reporting() != 0) {
+       if (error_reporting() & $err_no) {
                // report non-silenced errors
                echo "Error: $err_no - $err_msg, $filename($linenum)\n";
        }
index 4d7281b92b71d0045b6c35664adb26eafe648667..677a87103fc94ed636a43bcd13a42b8b47088577 100644 (file)
@@ -12,7 +12,7 @@ echo "*** Testing array_multisort() : usage variation ***\n";
 
 // Define error handler
 function test_error_handler($err_no, $err_msg, $filename, $linenum) {
-       if (error_reporting() != 0) {
+       if (error_reporting() & $err_no) {
                // report non-silenced errors
                echo "Error: $err_no - $err_msg, $filename($linenum)\n";
        }
index 994e27ecd04a77e5cf0575846eb6cf168c54e198..f9a00e9701dc553c1dd3169feb93657350e76b8c 100644 (file)
@@ -12,7 +12,7 @@ echo "*** Testing array_multisort() : usage variation ***\n";
 
 // Define error handler
 function test_error_handler($err_no, $err_msg, $filename, $linenum) {
-       if (error_reporting() != 0) {
+       if (error_reporting() & $err_no) {
                // report non-silenced errors
                echo "Error: $err_no - $err_msg, $filename($linenum)\n";
        }
index 5939b7bef994fc32691918b60ecca100824b27a6..c625d2a56606edf8894dd94eb206e873bdbd98db 100644 (file)
@@ -12,7 +12,7 @@ echo "*** Testing array_multisort() : usage variation ***\n";
 
 // Define error handler
 function test_error_handler($err_no, $err_msg, $filename, $linenum) {
-       if (error_reporting() != 0) {
+       if (error_reporting() & $err_no) {
                // report non-silenced errors
                echo "Error: $err_no - $err_msg, $filename($linenum)\n";
        }
index 1bf30340e4818e7a74b3d473f9710378cdea8159..5e18ce1948d60f06843455d24ea8526030a705ae 100644 (file)
@@ -14,7 +14,7 @@ echo "*** Testing file_put_contents() : usage variation ***\n";
 
 // Define error handler
 function test_error_handler($err_no, $err_msg, $filename, $linenum) {
-       if (error_reporting() != 0) {
+       if (error_reporting() & $err_no) {
                // report non-silenced errors
                echo "Error: $err_no - $err_msg, $filename($linenum)\n";
        }
index aaf18c077655846935fb6b6d4ab0300ab3e22668..8adddef2ee758eeef278fd0b5a161ee2de2939f6 100644 (file)
@@ -14,7 +14,7 @@ echo "*** Testing file_put_contents() : usage variation ***\n";
 
 // Define error handler
 function test_error_handler($err_no, $err_msg, $filename, $linenum) {
-       if (error_reporting() != 0) {
+       if (error_reporting() & $err_no) {
                // report non-silenced errors
                echo "Error: $err_no - $err_msg, $filename($linenum)\n";
        }
index 086161de6c327eb76f40c5e7ec83d4865931f9f9..e44bc1db805d20c72b690d2e81edab1814f311d4 100644 (file)
@@ -12,7 +12,7 @@ echo "*** Testing intval() : usage variation ***\n";
 
 // Define error handler
 function test_error_handler($err_no, $err_msg, $filename, $linenum) {
-       if (error_reporting() != 0) {
+       if (error_reporting() & $err_no) {
                // report non-silenced errors
                echo "Error: $err_no - $err_msg, $filename($linenum)\n";
        }