com php-src: Promote warnings to Error in FileInfo extension: ext/fileinfo/fileinfo.c ext/fileinfo/tests/finfo_file_0 01.phpt
ext/fileinfo/tests/finfo_file_basic.phpt ext/fileinfo/tests/mime_content_type_001.phpt
| From: | George Peter Banyard | Date: | Thu, 06 Aug 2020 11:37:36 +0000 |
| Subject: | com php-src: Promote warnings to Error in FileInfo extension: ext/fileinfo/fileinfo.c ext/fileinfo/tests/finfo_file_0 01.phpt ext/fileinfo/tests/finfo_file_basic.phpt ext/fileinfo/tests/mime_content_type_001.phpt |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-112598@lists.php.net to get a copy of this message | ||
Commit: 196f8fdfc3e792d316311b55e50a4ae4c97c5b71
Author: George Peter Banyard <girgias@php.net> Thu, 6 Aug 2020 13:37:36 +0200
Parents: b3f0f35fd7c6f87d1dbe36ce2c6b18e80c3d92f6
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=196f8fdfc3e792d316311b55e50a4ae4c97c5b71
Log:
Promote warnings to Error in FileInfo extension
Closes GH-5914
Changed paths:
M ext/fileinfo/fileinfo.c
M ext/fileinfo/tests/finfo_file_001.phpt
M ext/fileinfo/tests/finfo_file_basic.phpt
M ext/fileinfo/tests/mime_content_type_001.phpt
Diff:
diff --git a/ext/fileinfo/fileinfo.c b/ext/fileinfo/fileinfo.c
index 014c37441ae..2538171f25b 100644
--- a/ext/fileinfo/fileinfo.c
+++ b/ext/fileinfo/fileinfo.c
@@ -376,8 +376,8 @@ static void _php_finfo_get_type(INTERNAL_FUNCTION_PARAMETERS, int mode, int mime
break;
default:
- php_error_docref(NULL, E_WARNING, "Can only process string or stream arguments");
- RETURN_FALSE;
+ zend_argument_type_error(2, "must be of type resource|string, %s given",
zend_zval_type_name(what));
+ RETURN_THROWS();
}
magic = magic_open(MAGIC_MIME_TYPE);
@@ -439,14 +439,12 @@ static void _php_finfo_get_type(INTERNAL_FUNCTION_PARAMETERS, int mode, int
mime
php_stream_wrapper *wrap;
php_stream_statbuf ssb;
- if (buffer == NULL || !*buffer) {
- php_error_docref(NULL, E_WARNING, "Empty filename or path");
- RETVAL_FALSE;
+ if (buffer == NULL || buffer_len == 0) {
+ zend_argument_value_error(1, "cannot be empty");
goto clean;
}
if (CHECK_NULL_PATH(buffer, buffer_len)) {
- php_error_docref(NULL, E_WARNING, "Invalid path");
- RETVAL_FALSE;
+ zend_argument_type_error(1, "must not contain null bytes");
goto clean;
}
@@ -484,9 +482,7 @@ static void _php_finfo_get_type(INTERNAL_FUNCTION_PARAMETERS, int mode, int mime
}
break;
}
-
- default:
- php_error_docref(NULL, E_WARNING, "Can only process string or stream arguments");
+ EMPTY_SWITCH_DEFAULT_CASE()
}
common:
diff --git a/ext/fileinfo/tests/finfo_file_001.phpt b/ext/fileinfo/tests/finfo_file_001.phpt
index 3d01c8e8813..726103e02d6 100644
--- a/ext/fileinfo/tests/finfo_file_001.phpt
+++ b/ext/fileinfo/tests/finfo_file_001.phpt
@@ -6,22 +6,29 @@ finfo_file(): Testing file names
<?php
$fp = finfo_open();
-var_dump(finfo_file($fp, "\0"));
-var_dump(finfo_file($fp, ''));
-var_dump(finfo_file($fp, NULL));
+try {
+ var_dump(finfo_file($fp, "\0"));
+} catch (\TypeError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+try {
+ var_dump(finfo_file($fp, ''));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+try {
+ var_dump(finfo_file($fp, NULL));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
var_dump(finfo_file($fp, '.'));
var_dump(finfo_file($fp, '&'));
?>
--EXPECTF--
-Warning: finfo_file(): Empty filename or path in %s on line %d
-bool(false)
-
-Warning: finfo_file(): Empty filename or path in %s on line %d
-bool(false)
-
-Warning: finfo_file(): Empty filename or path in %s on line %d
-bool(false)
+finfo_file(): Argument #1 ($finfo) must not contain null bytes
+finfo_file(): Argument #1 ($finfo) cannot be empty
+finfo_file(): Argument #1 ($finfo) cannot be empty
string(9) "directory"
Warning: finfo_file(&): Failed to open stream: No such file or directory in %s on line %d
diff --git a/ext/fileinfo/tests/finfo_file_basic.phpt b/ext/fileinfo/tests/finfo_file_basic.phpt
index 1851058b131..816f826c1b5 100644
--- a/ext/fileinfo/tests/finfo_file_basic.phpt
+++ b/ext/fileinfo/tests/finfo_file_basic.phpt
@@ -13,14 +13,17 @@ echo "*** Testing finfo_file() : basic functionality ***\n";
var_dump( finfo_file( $finfo, __FILE__) );
var_dump( finfo_file( $finfo, __FILE__, FILEINFO_CONTINUE ) );
var_dump( finfo_file( $finfo, $magicFile ) );
-var_dump( finfo_file( $finfo, $magicFile.chr(0).$magicFile) );
+
+try {
+ var_dump( finfo_file( $finfo, $magicFile.chr(0).$magicFile) );
+} catch (\TypeError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
?>
---EXPECTF--
+--EXPECT--
*** Testing finfo_file() : basic functionality ***
string(28) "text/x-php; charset=us-ascii"
-string(%d) "PHP script, ASCII text%A"
+string(22) "PHP script, ASCII text"
string(32) "text/plain; charset=unknown-8bit"
-
-Warning: finfo_file(): Invalid path in %s%efinfo_file_basic.php on line %d
-bool(false)
+finfo_file(): Argument #1 ($finfo) must not contain null bytes
diff --git a/ext/fileinfo/tests/mime_content_type_001.phpt
b/ext/fileinfo/tests/mime_content_type_001.phpt
index 472d3e84f81..9e3cb603986 100644
--- a/ext/fileinfo/tests/mime_content_type_001.phpt
+++ b/ext/fileinfo/tests/mime_content_type_001.phpt
@@ -5,26 +5,47 @@ mime_content_type(): Testing wrong parameters
--FILE--
<?php
-mime_content_type(1);
-mime_content_type(NULL);
-mime_content_type(new stdclass);
-mime_content_type(array());
+try {
+ mime_content_type(1);
+} catch (\TypeError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+try {
+ mime_content_type(NULL);
+} catch (\TypeError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+try {
+ mime_content_type(new stdclass);
+} catch (\TypeError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+try {
+ mime_content_type(array());
+} catch (\TypeError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+
mime_content_type('foo/inexistent');
-mime_content_type('');
-mime_content_type("\0");
+
+try {
+ mime_content_type('');
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+try {
+ mime_content_type("\0");
+} catch (\TypeError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
?>
--EXPECTF--
-Warning: mime_content_type(): Can only process string or stream arguments in %s on line %d
-
-Warning: mime_content_type(): Can only process string or stream arguments in %s on line %d
-
-Warning: mime_content_type(): Can only process string or stream arguments in %s on line %d
-
-Warning: mime_content_type(): Can only process string or stream arguments in %s on line %d
+mime_content_type(): Argument #2 must be of type resource|string, int given
+mime_content_type(): Argument #2 must be of type resource|string, null given
+mime_content_type(): Argument #2 must be of type resource|string, stdClass given
+mime_content_type(): Argument #2 must be of type resource|string, array given
Warning: mime_content_type(foo/inexistent): Failed to open stream: No such file or directory in %s
on line %d
-
-Warning: mime_content_type(): Empty filename or path in %s on line %d
-
-Warning: mime_content_type(): Empty filename or path in %s on line %d
+mime_content_type(): Argument #1 ($filename) cannot be empty
+mime_content_type(): Argument #1 ($filename) must not contain null bytes