Skip to content

Commit 3d41cb0

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 8c266e8 commit 3d41cb0

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

ext/fileinfo/fileinfo.c

Lines changed: 7 additions & 12 deletions
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,9 @@ PHP_FUNCTION(finfo_set_flags)
276268
}
277269
FILEINFO_FROM_OBJECT(finfo, self);
278270

279-
FINFO_SET_OPTION(finfo->magic, options)
271+
/* We do not check the return value as it can only ever fail if options contains MAGIC_PRESERVE_ATIME
272+
* and the system neither has utime(3) nor utimes(2). Something incredibly unlikely. */
273+
magic_setflags(finfo->magic, options);
280274
finfo->options = options;
281275

282276
RETURN_TRUE;
@@ -337,7 +331,9 @@ static void _php_finfo_get_type(INTERNAL_FUNCTION_PARAMETERS, int mode, int mime
337331

338332
/* Set options for the current file/buffer. */
339333
if (options) {
340-
FINFO_SET_OPTION(magic, options)
334+
/* We do not check the return value as it can only ever fail if options contains MAGIC_PRESERVE_ATIME
335+
* and the system neither has utime(3) nor utimes(2). Something incredibly unlikely. */
336+
magic_setflags(magic, options);
341337
}
342338

343339
switch (mode) {
@@ -436,9 +432,8 @@ static void _php_finfo_get_type(INTERNAL_FUNCTION_PARAMETERS, int mode, int mime
436432

437433
/* Restore options */
438434
if (options) {
439-
FINFO_SET_OPTION(magic, finfo->options)
435+
magic_setflags(magic, finfo->options);
440436
}
441-
return;
442437
}
443438
/* }}} */
444439

0 commit comments

Comments
 (0)