Project

General

Profile

Actions

Bug #17535

closed

index.php assumes current working directory to be PATH_site

Added by Peter Dinges over 17 years ago. Updated about 6 years ago.

Status:
Closed
Priority:
Should have
Assignee:
Category:
Communication
Target version:
-
Start date:
2007-08-16
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
4.1
PHP Version:
5.2
Tags:
Complexity:
Is Regression:
Sprint Focus:

Description

After a recent PHP upgrade from 5.1.2-r3 to 5.2.4_pre200708051230-r2 on Gentoo Linux, the Typo3 frontend suddenly stopped working. After some investigation it turned out that the current working directory used in index.php is no longer the link source directory "PATH_site/", but the link target "/path/to/typo3_src/". Therefore, the relative paths used to include libraries via TS, like in my case templavoila, were no longer found.

Attached patch changes the current working directory to PATH_site at the very beginning of index.php. Thus, the assumptions about the CWD are fulfilled again.

It might be that this is a Gentoo specific PHP issue. After all, they seem to use a pre-release. However, clarifying the made assumptions about the CWD does not harm either.

Maybe someone with a test server can check PHP's beavhiour regarding the CWD of linked files in different versions. Consider the following test setup:
$ mkdir $HTDOCS/bar/
$ echo '' > $HTDOCS/bar/foo.php
$ ln -s $HTDOCS/bar/foo.php $HTDOCS/foo.php

It seems that the expected and old output of http://host/foo.php is "$HTDOCS". In my setup however, the output is "$HTDOCS/bar".

Setup: Apache 2.2.4-r11 with mod_fcgid and PHP 5.2.4_pre200708051230-r2 (FastCGI) on Gentoo Linux.
(issue imported from #M6158)


Files

typo3_src-4.1.2-site_path_cwd.patch (948 Bytes) typo3_src-4.1.2-site_path_cwd.patch Administrator Admin, 2007-08-16 08:02
0006158.patch (1.19 KB) 0006158.patch Administrator Admin, 2008-02-04 14:45
0006158_v2.patch (1.27 KB) 0006158_v2.patch Administrator Admin, 2008-02-04 23:42

Related issues 1 (0 open1 closed)

Related to TYPO3 Core - Bug #14692: Access to file resources does not work with mod_fcgidClosed2005-04-20

Actions
Actions #1

Updated by Christian Hoffmann about 17 years ago

Peter, Thanks for the extensive bug description and the patch. I just hit that problem as well and tracked it down further. It's not a Gentoo-specific problem (we just got hit by it first as we are packaging this snapshot).
It was this commit: http://cvs.php.net/viewcvs.cgi/php-src/sapi/cgi/cgi_main.c?r1=1.267.2.15.2.42&r2=1.267.2.15.2.43&pathrev=PHP_5_2 (Fixed bug #40419 (Trailing Slash in CGI request don't work)).
I think this is a pretty important behaviour change and may have been unintended. Please report such changes/bugs to our bugzilla (http://bugs.gentoo.org) if you are not sure whether it is Gentoo-specific and in any other cases to http://bugs.php.net/
Thanks.

Also, I just sent a mail to Dmitry (who made that commit), CCing Ilia (5.2 RM) to make sure this is really intended. If it is, your patch should probably applied as a lot of installations are likely to break otherwise.

Actions #2

Updated by Christian Hoffmann about 17 years ago

Current status is that this bug will probably not fixed for 5.2.4, but in a later version...
Including Peter's patch into the official Typo3 source would probably be a good idea since it will be a long time to 5.2.5, I guess.

Actions #3

Updated by Oliver Hader about 17 years ago

The link to the PHP bug:
http://bugs.php.net/bug.php?id=40419

The C-patch shows that it only happens if cgi.fix_pathinfo in php.ini is enabled.

From http://www.php.net/manual/en/ini.core.php:
<b>cgi.fix_pathinfo boolean</b>

Provides real PATH_INFO/PATH_TRANSLATED support for CGI. PHP's previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok what PATH_INFO is. For more information on PATH_INFO, see the cgi specs. Setting this to 1 will cause PHP CGI to fix it's paths to conform to the spec. A setting of zero causes PHP to behave as before. Default is zero. You should fix your scripts to use SCRIPT_FILENAME rather than PATH_TRANSLATED.
Actions #4

Updated by Michael Stucki about 17 years ago

Thanks to Peter for providing a workaround. However, I'm not sure if this could have any side effects. And even if not, it's clearly a PHP bug which will hopefully get fixed quite soon.

I suggest to leave this patch out of TYPO3core and patch affected installations manually until PHP has fixed the issue.

Actions #5

Updated by Michael Stucki about 17 years ago

Reopening this bug to make it possible to add more comments on this.

Actions #6

Updated by Ingmar Schlecht about 17 years ago

What about only doing the chdir(PATH_site) only for the specific PHP versions affected:

Pseudo code:
if(php version > 5.2 && cgi.fix_pathinfo) {
chdir(PATH_site);
}

Actions #7

Updated by Michael Stucki about 17 years ago

Agreed. Who's gonna update the patch?

Actions #8

Updated by Christian Hoffmann about 17 years ago

Dmitry (Zend) asked me to open a php bug, so I filed http://bugs.php.net/bug.php?id=42587

Until now I didn't manage to get Typo3 working without patching PHP (i.e. above patch doesn't work for me). I'll try to track it down further.

Actions #9

Updated by Christian Hoffmann about 17 years ago

Really too lazy to dig through the whole Typo3/TS/TemplaVoila code, I'm now using the simplest workaround: Don't use a index.php symlink, just copy the file from typo3_src/. Shouldn't cause too many problems with updates as this file doesn't look like it's subject to heavy changes.

Actions #10

Updated by Bjrn Kraus about 17 years ago

Here is the code:

if (version_compare(PHP_VERSION, '5.2', '>') && ini_get('cgi.fix_pathinfo') == '1')
chdir(PATH_site);

@Michael:
If you agree with this I will post a patch file for it.

Actions #11

Updated by Michael Stucki about 17 years ago

So Chrstian says that you can work around the issue while Björn prefers the fix. What should we do?

Actions #12

Updated by Bjrn Kraus about 17 years ago

As I posted on the list, the php.ini setting doesn't work for me running php as fastcgi. The fix seems to be the only solution that works for all configurations.

Actions #13

Updated by Bjrn Kraus about 17 years ago

The php bug has been fixed in svn (see http://bugs.php.net/bug.php?id=40419 ). Perhaps someone can give it a try.

Actions #14

Updated by Christian Hoffmann about 17 years ago

The fix from php-cvs works for me. Anybody who hits the problem should just apply http://cvs.php.net/viewcvs.cgi/php-src/sapi/cgi/cgi_main.c?r1=1.267.2.15.2.48&r2=1.267.2.15.2.49&pathrev=PHP_5_2 and recompile...
For Gentoo, we are going to include this patch in our next revision (php-5.2.4-r1).

Actions #15

Updated by Bjrn Kraus about 17 years ago

I'm currently testing the new PHP version. The bug seems to be fixed in PHP 5.2.5. There is no patching of index.php needed anymore.

Actions #16

Updated by Oliver Hader almost 17 years ago

I can confirm this on PHP 5.2.4-2+b1/Debian with fcgid.

Actions #17

Updated by Oliver Hader almost 17 years ago

Summary: This PHP bug was introduced in 5.2.4 and fixed in 5.2.5.
However, Debian delivers 5.2.4-2+b1 which still contains this bug.
The behaviour only occours if cgi.fix_pathinfo is set (thus CGI mode only), as it can be seen in sapi/cgi/cgi_main.c.

The attached patch checks the PHP versions, the PHP setting and if the current directory is different to PATH_site. If these conditions are met, the chdir(PATH_site) is executed.

Actions #18

Updated by Oliver Hader almost 17 years ago

Had logical bug in first patch. New version attached.

Actions #19

Updated by Oliver Hader almost 17 years ago

Debian/Testing has now "PHP 5.2.5-2" which doesn't have the PHP bug anymore.
Since there is not much feedback concerning this issue anymore, I tend to drop the RFC in the Core List. But whoever it needs the patch is still here in the bugtracker.

Actions #20

Updated by Maldonado over 16 years ago

I can confirm this issue with the php5-cgi (5.2.4-2ubuntu5) version, that is delivered with Ubuntu 8.04 Hardy Heron.

Setting cgi.fix_pathinfo = 0 in the php.ini file fixes it.

Actions #21

Updated by Michael Stucki over 16 years ago

I think that this is closely related to bug #14692 and although it's not exactly the same problem, it could likely be solved with the same change.

I never liked the way of chdir()'ing into PATH_site, I rather think that non-absolute paths are wrong and need to be fixed.

Please check if the patch in #14692 solves your problem as well.

Actions #22

Updated by Oliver Hader over 15 years ago

This issue is dropped since it was a work-around for a PHP misbehaviour.

Actions #23

Updated by Benni Mack about 6 years ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF