Skip to content

Commit c4d6e62

Browse files
committed
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.
1 parent 70ff10a commit c4d6e62

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

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)