Skip to content

Commit fa10abd

Browse files
committed
Fix #79491: Search for .user.ini extends up to root dir
The `start` parameter of `php_cgi_ini_activate_user_config` is supposed to hold the byte offset of the doc root in the given `path`. However, the current expression which fixes a potential type incompatibility will ever only evaluate to zero or one, because it uses the *logical* and operator (`&&`). Furthermore we notice that subtracting one from `doc_root_len` is not necessary, so there is even no need for the `start` parameter at all.
1 parent f62571c commit fa10abd

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ PHP NEWS
1111
. Fixed bug #78221 (DOMNode::normalize() doesn't remove empty text nodes).
1212
(cmb)
1313

14+
- FCGI:
15+
. Fixed bug #79491 (Search for .user.ini extends up to root dir). (cmb)
16+
1417
- MBString:
1518
. Fixed bug #79441 (Segfault in mb_chr() if internal encoding is unsupported).
1619
(Girgias)

sapi/cgi/cgi_main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ static void sapi_cgi_log_message(char *message, int syslog_type_int)
789789

790790
/* {{{ php_cgi_ini_activate_user_config
791791
*/
792-
static void php_cgi_ini_activate_user_config(char *path, size_t path_len, const char *doc_root, size_t doc_root_len, int start)
792+
static void php_cgi_ini_activate_user_config(char *path, size_t path_len, const char *doc_root, size_t doc_root_len)
793793
{
794794
user_config_cache_entry *new_entry, *entry;
795795
time_t request_time = (time_t)sapi_get_request_time();
@@ -842,7 +842,7 @@ static void php_cgi_ini_activate_user_config(char *path, size_t path_len, const
842842
#else
843843
if (strncmp(s1, s2, s_len) == 0) {
844844
#endif
845-
char *ptr = s2 + start; /* start is the point where doc_root ends! */
845+
char *ptr = s2 + doc_root_len;
846846
while ((ptr = strchr(ptr, DEFAULT_SLASH)) != NULL) {
847847
*ptr = 0;
848848
php_parse_user_ini_file(path, PG(user_ini_filename), entry->user_config);
@@ -938,7 +938,7 @@ static int sapi_cgi_activate(void)
938938
doc_root = estrndup(doc_root, doc_root_len);
939939
zend_str_tolower(doc_root, doc_root_len);
940940
#endif
941-
php_cgi_ini_activate_user_config(path, path_len, doc_root, doc_root_len, (doc_root_len > 0 && (doc_root_len - 1)));
941+
php_cgi_ini_activate_user_config(path, path_len, doc_root, doc_root_len);
942942

943943
#ifdef PHP_WIN32
944944
efree(doc_root);

0 commit comments

Comments
 (0)