Skip to content

Deduplicate error-handling code in finfo_open #19149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 17, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Deduplicate error-handling code in finfo_open
  • Loading branch information
nielsdos committed Jul 16, 2025
commit 9766ce6a2112ad60a9761e416ab5c0bb4ae9c7f8
42 changes: 14 additions & 28 deletions ext/fileinfo/fileinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,22 +153,10 @@ PHP_FUNCTION(finfo_open)
} else if (file && *file) { /* user specified file, perform open_basedir checks */

if (php_check_open_basedir(file)) {
if (object) {
zend_restore_error_handling(&zeh);
if (!EG(exception)) {
zend_throw_exception(NULL, "Constructor failed", 0);
}
}
RETURN_FALSE;
goto err;
}
if (!expand_filepath_with_mode(file, resolved_path, NULL, 0, CWD_EXPAND)) {
if (object) {
zend_restore_error_handling(&zeh);
if (!EG(exception)) {
zend_throw_exception(NULL, "Constructor failed", 0);
}
}
RETURN_FALSE;
goto err;
}
file = resolved_path;
}
Expand All @@ -177,37 +165,35 @@ PHP_FUNCTION(finfo_open)

if (magic == NULL) {
php_error_docref(NULL, E_WARNING, "Invalid mode '" ZEND_LONG_FMT "'.", options);
if (object) {
zend_restore_error_handling(&zeh);
if (!EG(exception)) {
zend_throw_exception(NULL, "Constructor failed", 0);
}
}
RETURN_FALSE;
goto err;
}

if (magic_load(magic, file) == -1) {
php_error_docref(NULL, E_WARNING, "Failed to load magic database at \"%s\"", file);
magic_close(magic);
if (object) {
zend_restore_error_handling(&zeh);
if (!EG(exception)) {
zend_throw_exception(NULL, "Constructor failed", 0);
}
}
RETURN_FALSE;
goto err;
}

if (object) {
zend_restore_error_handling(&zeh);
finfo_object *obj = Z_FINFO_P(object);
obj->magic = magic;
return;
} else {
zend_object *zobj = finfo_objects_new(finfo_class_entry);
finfo_object *obj = php_finfo_fetch_object(zobj);
obj->magic = magic;
RETURN_OBJ(zobj);
}

err:
if (object) {
zend_restore_error_handling(&zeh);
if (!EG(exception)) {
zend_throw_exception(NULL, "Constructor failed", 0);
}
}
RETURN_FALSE;
}
/* }}} */

Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy