Skip to content

Propagate errors correctly in ps_files_cleanup_dir() #10644

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

Closed
wants to merge 1 commit into from

Conversation

nielsdos
Copy link
Member

@nielsdos nielsdos commented Feb 21, 2023

In SessionHandler::gc, we use a virtual call to PS(default_mod)->s_gc to call the gc implementation. That return value is checked against FAILURE.
One of the call targets of PS(default_mod)->s_gc is ps_gc_files(). ps_gc_files() calls to ps_files_cleanup_dir(). The latter function has some error checks and outputs a notice if something goes wrong. In cases of errors, the function returns 0. This means that the check in SessionHandler::gc will misinterpret this as a success and report that 0 files have been successfully cleaned up. Fix it by returning -1 to indicate something did go wrong.

Found using an experimental static analyser I'm developing.

@devnexen
Copy link
Member

Should not you change the return type as well ?

@nielsdos
Copy link
Member Author

nielsdos commented Feb 21, 2023

zend_result is not appropriate, because the function here returns a value >= 0 on success. The only two valid values for zend_result are SUCCESS and FAILURE.

@devnexen
Copy link
Member

devnexen commented Feb 21, 2023

maybe just returning -1 might be more appropriate then, usually those constants are for zend_result. otherwise LGTM to me.

@nielsdos
Copy link
Member Author

The result is eventually compared to FAILURE though. If FAILURE would ever change its value this could cause problems.

@Girgias
Copy link
Member

Girgias commented Feb 21, 2023

The result is eventually compared to FAILURE though. If FAILURE would ever change its value this could cause problems.

I'd rather not have FAILURE be used somewhere which doesn't not explicitly return a zend_result, as if we ever want to change them, e.g. by aliasing them to false and type deffing zend_result to bool it's going to be a pain to figure out which places break.

In SessionHandler::gc, we use a virtual call to PS(default_mod)->s_gc to
call the gc implementation. That return value is checked against
FAILURE (-1).
One of the call targets of PS(default_mod)->s_gc is ps_gc_files().
ps_gc_files() calls to ps_files_cleanup_dir(). The latter function has
some error checks and outputs a notice if something goes wrong. In cases
of errors, the function returns 0. This means that the check in
SessionHandler::gc will misinterpret this as a success and report that 0
files have been *successfully* cleaned up. Fix it by returning -1 to
indicate something *did* go wrong.
@nielsdos
Copy link
Member Author

Okay, I changed it. Thx

@devnexen devnexen closed this in da3ce60 Feb 21, 2023
@devnexen
Copy link
Member

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants