Skip to content

Commit 0efd70c

Browse files
committed
ext/fileinfo: Use magic_setflags() directly
The only way this function returns -1 is if: > magic_setflags() returns -1 on systems that don't support utime(3), or utimes(2) when MAGIC_PRESERVE_ATIME is set. This is extremely unlikely and if this would happen we currently have a return type violation.
1 parent 24fbe2d commit 0efd70c

File tree

2 files changed

+4
-13
lines changed

2 files changed

+4
-13
lines changed

ext/fileinfo/fileinfo.c

+3-12
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,6 @@ PHP_FILEINFO_API zend_object *finfo_objects_new(zend_class_entry *class_type)
9494
}
9595
/* }}} */
9696

97-
#define FINFO_SET_OPTION(magic, options) \
98-
if (magic_setflags(magic, options) == -1) { \
99-
php_error_docref(NULL, E_WARNING, "Failed to set option '" ZEND_LONG_FMT "' %d:%s", \
100-
options, magic_errno(magic), magic_error(magic)); \
101-
RETURN_FALSE; \
102-
}
103-
/* }}} */
104-
10597
/* {{{ PHP_MINIT_FUNCTION */
10698
PHP_MINIT_FUNCTION(finfo)
10799
{
@@ -276,7 +268,7 @@ PHP_FUNCTION(finfo_set_flags)
276268
}
277269
FILEINFO_FROM_OBJECT(finfo, self);
278270

279-
FINFO_SET_OPTION(finfo->magic, options)
271+
magic_setflags(finfo->magic, options);
280272
finfo->options = options;
281273

282274
RETURN_TRUE;
@@ -337,7 +329,7 @@ static void _php_finfo_get_type(INTERNAL_FUNCTION_PARAMETERS, int mode, int mime
337329

338330
/* Set options for the current file/buffer. */
339331
if (options) {
340-
FINFO_SET_OPTION(magic, options)
332+
magic_setflags(magic, options);
341333
}
342334

343335
switch (mode) {
@@ -436,9 +428,8 @@ static void _php_finfo_get_type(INTERNAL_FUNCTION_PARAMETERS, int mode, int mime
436428

437429
/* Restore options */
438430
if (options) {
439-
FINFO_SET_OPTION(magic, finfo->options)
431+
magic_setflags(magic, options);
440432
}
441-
return;
442433
}
443434
/* }}} */
444435

ext/fileinfo/tests/finfo_file_basic.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ try {
2424
*** Testing finfo_file() : basic functionality ***
2525
string(28) "text/x-php; charset=us-ascii"
2626
string(22) "PHP script, ASCII text"
27-
string(29) "text/x-file; charset=us-ascii"
27+
string(43) "magic text file for file(1) cmd, ASCII text"
2828
finfo_file(): Argument #2 ($filename) must not contain any null bytes

0 commit comments

Comments
 (0)