Commit e2d3cee9ad4 for php
commit e2d3cee9ad4b0b739f4a8ebe6a69c938399b7da6
Author: Ilija Tovilo <ilija.tovilo@me.com>
Date: Wed Nov 11 16:53:47 2026 +0100
Fix GHSA-fm2m-fjf5-v3cp: RCE via corrupted session file
If the session write is interrupted, and the previous session file wasn't
truncated, we can end up with two partial sessions concatenated together. The
approximate location of failure may be attacker-controllable in threaded
environments if another thread causes the process to _exit().
diff --git a/ext/session/mod_files.c b/ext/session/mod_files.c
index 9396f16b935..c619b26bd22 100644
--- a/ext/session/mod_files.c
+++ b/ext/session/mod_files.c
@@ -236,9 +236,9 @@ static zend_result ps_files_write(ps_files *data, zend_string *key, zend_string
return FAILURE;
}
- /* Truncate file if the amount of new data is smaller than the existing data set. */
- if (ZSTR_LEN(val) < data->st_size) {
- php_ignore_value(ftruncate(data->fd, 0));
+ if (ftruncate(data->fd, 0) != 0) {
+ php_error_docref(NULL, E_WARNING, "ftruncate() failed: %s (%d)", strerror(errno), errno);
+ return FAILURE;
}
#ifdef HAVE_PWRITE