|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2004-12-28 17:21 UTC] julien dot mathieu at gmail dot com
Description: ------------ session files created by session_start always exist but randomly have different permission (rw or r). directory has full permissions Sometimes files have r+w -> ok Sometimes only r -> session_start(): open(/tmp/sess_a3a79ce3bd2df9289a325a206c1dfc84, O_RDWR) failed: Permission denied (13) in ... Its nearly a random problem but happens 25% of time Reproduce code: --------------- <?php session_start() ... PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 08 19:00:01 2025 UTC |
I can confirm this bug happening on php 4.4.2 build as apache 2 (with prefork) module. It's extremaly difficult to reproduce, but with little research it seems to be somehow umask related. The following is from strace running on a apache process that creates the files with wrong permissions open("/tmp/sess_5b2929b94cf141335d0b2d1e5a38fc29", O_RDWR|O_CREAT, 0600) = 186 fstat64(186, {st_mode=S_IFREG|0400, st_size=0, ...}) = 0 So php creates file with 600 permissions but it has only 400 in final. Note that's happening very rarely, normally file is created with 600. I didn't have luck tracing how and when umask is changing during request processing (probably something is changing it prior to the request, so possibly it's not even php related), but I tried to make the following very dirty workaround in ext/session/mod_files.c: ------------------------------------------------ @@ -138,6 +138,7 @@ static void ps_files_open(ps_files *data, const char *key TSRMLS_DC) { char buf[MAXPATHLEN]; + mode_t orig_mask; if (data->fd < 0 || !data->lastkey || strcmp(key, data->lastkey)) { if (data->lastkey) { @@ -156,8 +157,10 @@ data->lastkey = estrdup(key); + orig_mask = umask(0); data->fd = VCWD_OPEN_MODE(buf, O_CREAT | O_RDWR | O_BINARY, 0600); - + umask(orig_mask); + ------------------------------------------------ No matter how ugly it is - it seems to do the job and session files with wrong permissions are no longer created (this workaround is probably bad idea on threaded severs though).