Skip to content

Commit da3ce60

Browse files
nielsdosdevnexen
authored andcommitted
Propagate errors correctly in ps_files_cleanup_dir()
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. Closes GH-10644.
1 parent 74c880e commit da3ce60

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ PHP NEWS
5353
. Fixed bug GH-10623 (Reflection::getClosureUsedVariables opcode fix with
5454
variadic arguments). (nielsdos)
5555

56+
- Session:
57+
. Fixed ps_files_cleanup_dir() on failure code paths with -1 instead of 0 as
58+
the latter was considered success by callers. (nielsdos).
59+
5660
- Standard:
5761
. Fixed bug GH-10292 (Made the default value of the first param of srand() and
5862
mt_srand() unknown). (kocsismate)

ext/session/mod_files.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ static int ps_files_cleanup_dir(const char *dirname, zend_long maxlifetime)
292292
dir = opendir(dirname);
293293
if (!dir) {
294294
php_error_docref(NULL, E_NOTICE, "ps_files_cleanup_dir: opendir(%s) failed: %s (%d)", dirname, strerror(errno), errno);
295-
return (0);
295+
return -1;
296296
}
297297

298298
time(&now);
@@ -302,7 +302,7 @@ static int ps_files_cleanup_dir(const char *dirname, zend_long maxlifetime)
302302
if (dirname_len >= MAXPATHLEN) {
303303
php_error_docref(NULL, E_NOTICE, "ps_files_cleanup_dir: dirname(%s) is too long", dirname);
304304
closedir(dir);
305-
return (0);
305+
return -1;
306306
}
307307

308308
/* Prepare buffer (dirname never changes) */

0 commit comments

Comments
 (0)