Skip to content

Commit 9e98e99

Browse files
committed
Revert "Fixed bug #75287 (Builtin webserver crash after chdir in a shutdown function)"
This reverts commit 816758e. After this commit relative router scripts were resolved against docroot rather than shell cwd.
1 parent cecf734 commit 9e98e99

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

sapi/cli/php_cli_server.c

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2126,6 +2126,12 @@ static int php_cli_server_dispatch_router(php_cli_server *server, php_cli_server
21262126
{
21272127
int decline = 0;
21282128
zend_file_handle zfd;
2129+
char *old_cwd;
2130+
2131+
ALLOCA_FLAG(use_heap)
2132+
old_cwd = do_alloca(MAXPATHLEN, use_heap);
2133+
old_cwd[0] = '\0';
2134+
php_ignore_value(VCWD_GETCWD(old_cwd, MAXPATHLEN - 1));
21292135

21302136
zfd.type = ZEND_HANDLE_FILENAME;
21312137
zfd.filename = server->router;
@@ -2147,6 +2153,12 @@ static int php_cli_server_dispatch_router(php_cli_server *server, php_cli_server
21472153
}
21482154
} zend_end_try();
21492155

2156+
if (old_cwd[0] != '\0') {
2157+
php_ignore_value(VCWD_CHDIR(old_cwd));
2158+
}
2159+
2160+
free_alloca(old_cwd, use_heap);
2161+
21502162
return decline;
21512163
}
21522164
/* }}} */
@@ -2338,20 +2350,10 @@ static int php_cli_server_ctor(php_cli_server *server, const char *addr, const c
23382350

23392351
if (router) {
23402352
size_t router_len = strlen(router);
2341-
if (!IS_ABSOLUTE_PATH(router, router_len)) {
2342-
_router = pemalloc(server->document_root_len + router_len + 2, 1);
2343-
if (!_router) {
2344-
retval = FAILURE;
2345-
goto out;
2346-
}
2347-
snprintf(_router,
2348-
server->document_root_len + router_len + 2, "%s%c%s", server->document_root, DEFAULT_SLASH, router);
2349-
} else {
2350-
_router = pestrndup(router, router_len, 1);
2351-
if (!_router) {
2352-
retval = FAILURE;
2353-
goto out;
2354-
}
2353+
_router = pestrndup(router, router_len, 1);
2354+
if (!_router) {
2355+
retval = FAILURE;
2356+
goto out;
23552357
}
23562358
server->router = _router;
23572359
server->router_len = router_len;

0 commit comments

Comments
 (0)