Skip to content

Commit 38553e8

Browse files
author
Yasuo Ohgaki
committed
Fixed Bug #68015 Session does not report invalid uid for files save handler
1 parent b1f33db commit 38553e8

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ PHP NEWS
2424
. Fixed bug #72590 (Opcache restart with kill_all_lockers does not work).
2525
(Keyur) (julien backport)
2626

27+
- Session:
28+
. Fixed bug #68015 (Session does not report invalid uid for files save handler).
29+
(Yasuo)
30+
2731
- Zip:
2832
. Fixed bug #70752 (Depacking with wrong password leaves 0 length files).
2933
(cmb)

ext/session/mod_files.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ static void ps_files_open(ps_files *data, const char *key TSRMLS_DC)
138138
}
139139

140140
if (!ps_files_path_create(buf, sizeof(buf), data, key)) {
141+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to create session data file path. Too short session ID, invalid save_path or path lentgth exceeds MAXPATHLEN(%d)", MAXPATHLEN);
141142
return;
142143
}
143144

@@ -147,7 +148,7 @@ static void ps_files_open(ps_files *data, const char *key TSRMLS_DC)
147148
#ifdef O_NOFOLLOW
148149
data->fd = VCWD_OPEN_MODE(buf, O_CREAT | O_RDWR | O_BINARY | O_NOFOLLOW, data->filemode);
149150
#else
150-
/* Check to make sure that the opened file is not outside of allowable dirs.
151+
/* Check to make sure that the opened file is not outside of allowable dirs.
151152
This is not 100% safe but it's hard to do something better without O_NOFOLLOW */
152153
if(PG(open_basedir) && lstat(buf, &sbuf) == 0 && S_ISLNK(sbuf.st_mode) && php_check_open_basedir(buf TSRMLS_CC)) {
153154
return;
@@ -162,6 +163,7 @@ static void ps_files_open(ps_files *data, const char *key TSRMLS_DC)
162163
if (fstat(data->fd, &sbuf) || (sbuf.st_uid != 0 && sbuf.st_uid != getuid() && sbuf.st_uid != geteuid())) {
163164
close(data->fd);
164165
data->fd = -1;
166+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Session data file is not created by your uid");
165167
return;
166168
}
167169
#endif

ext/session/tests/016.phpt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,9 @@ session_write_close();
2222
print "I live\n";
2323
?>
2424
--EXPECTF--
25-
Warning: session_write_close(): Failed to write session data (files). Please verify that the current setting of session.save_path is correct (123;:/really%scompletely:::/invalid;;,23123;213) in %s on line %d
26-
I live
25+
Warning: session_start(): Failed to create session data file path. Too short session ID, invalid save_path or path lentgth exceeds MAXPATHLEN(%d) in %s on line 4
26+
27+
Warning: session_write_close(): Failed to create session data file path. Too short session ID, invalid save_path or path lentgth exceeds MAXPATHLEN(%d) in %s on line 6
28+
29+
Warning: session_write_close(): Failed to write session data (files). Please verify that the current setting of session.save_path is correct (123;:/really\completely:::/invalid;;,23123;213) in %s on line 6
30+
I live

0 commit comments

Comments
 (0)