summaryrefslogtreecommitdiff
path: root/ext/fileinfo
diff options
context:
space:
mode:
authorFelipe Pena <felipe@php.net>2008-09-01 23:44:00 +0000
committerFelipe Pena <felipe@php.net>2008-09-01 23:44:00 +0000
commitd13b704d2572896f50f5644ec5f4291e09db94c5 (patch)
treecdad99e547486c7142949d5e3fe188b32cdf21ac /ext/fileinfo
parent606e0f26a0f9779047b34a9a026d121f116c4865 (diff)
downloadphp-git-d13b704d2572896f50f5644ec5f4291e09db94c5.tar.gz
- Fixed mime_content_type() behavior when a string is given
- Fixed check for "empty file name" - MFH: New test
Diffstat (limited to 'ext/fileinfo')
-rw-r--r--ext/fileinfo/fileinfo.c6
-rw-r--r--ext/fileinfo/tests/finfo_file_001.phpt1
-rw-r--r--ext/fileinfo/tests/mime_content_type_001.phpt28
3 files changed, 34 insertions, 1 deletions
diff --git a/ext/fileinfo/fileinfo.c b/ext/fileinfo/fileinfo.c
index 695fced4e4..d859d6732a 100644
--- a/ext/fileinfo/fileinfo.c
+++ b/ext/fileinfo/fileinfo.c
@@ -437,6 +437,7 @@ static void _php_finfo_get_type(INTERNAL_FUNCTION_PARAMETERS, int mode, int mime
case IS_STRING:
buffer = Z_STRVAL_P(what);
buffer_len = Z_STRLEN_P(what);
+ mode = FILEINFO_MODE_FILE;
break;
case IS_RESOURCE:
@@ -505,7 +506,7 @@ static void _php_finfo_get_type(INTERNAL_FUNCTION_PARAMETERS, int mode, int mime
php_stream_wrapper *wrap;
struct stat sb;
- if (buffer_len < 1) {
+ if (buffer == NULL || !*buffer) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Empty filename or path");
RETURN_FALSE;
}
@@ -523,6 +524,9 @@ static void _php_finfo_get_type(INTERNAL_FUNCTION_PARAMETERS, int mode, int mime
php_stream *stream = php_stream_open_wrapper_ex(buffer, "rb", ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL, context);
if (!stream) {
+ if (mimetype_emu) {
+ magic_close(magic);
+ }
RETURN_FALSE;
}
diff --git a/ext/fileinfo/tests/finfo_file_001.phpt b/ext/fileinfo/tests/finfo_file_001.phpt
index e35696915b..6472e920b1 100644
--- a/ext/fileinfo/tests/finfo_file_001.phpt
+++ b/ext/fileinfo/tests/finfo_file_001.phpt
@@ -12,6 +12,7 @@ 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
diff --git a/ext/fileinfo/tests/mime_content_type_001.phpt b/ext/fileinfo/tests/mime_content_type_001.phpt
new file mode 100644
index 0000000000..dd6ce07657
--- /dev/null
+++ b/ext/fileinfo/tests/mime_content_type_001.phpt
@@ -0,0 +1,28 @@
+--TEST--
+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());
+mime_content_type('foo/inexistent');
+mime_content_type('');
+mime_content_type("\0");
+
+?>
+--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
+
+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