Skip to content

Commit 816758e

Browse files
committed
Fixed bug #75287 (Builtin webserver crash after chdir in a shutdown function)
1 parent 397f5cb commit 816758e

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ PHP NEWS
66
. Fixed bug #75368 (mmap/munmap trashing on unlucky allocations). (Nikita,
77
Dmitry)
88

9+
- CLI:
10+
. Fixed bug #75287 (Builtin webserver crash after chdir in a shutdown
11+
function). (Laruence)
12+
913
- Exif:
1014
. Fixed bug #75301 (Exif extension has built in revision version). (Peter
1115
Kokot)

sapi/cli/php_cli_server.c

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2106,12 +2106,6 @@ static int php_cli_server_dispatch_router(php_cli_server *server, php_cli_server
21062106
{
21072107
int decline = 0;
21082108
zend_file_handle zfd;
2109-
char *old_cwd;
2110-
2111-
ALLOCA_FLAG(use_heap)
2112-
old_cwd = do_alloca(MAXPATHLEN, use_heap);
2113-
old_cwd[0] = '\0';
2114-
php_ignore_value(VCWD_GETCWD(old_cwd, MAXPATHLEN - 1));
21152109

21162110
zfd.type = ZEND_HANDLE_FILENAME;
21172111
zfd.filename = server->router;
@@ -2133,12 +2127,6 @@ static int php_cli_server_dispatch_router(php_cli_server *server, php_cli_server
21332127
}
21342128
} zend_end_try();
21352129

2136-
if (old_cwd[0] != '\0') {
2137-
php_ignore_value(VCWD_CHDIR(old_cwd));
2138-
}
2139-
2140-
free_alloca(old_cwd, use_heap);
2141-
21422130
return decline;
21432131
}
21442132
/* }}} */
@@ -2330,10 +2318,20 @@ static int php_cli_server_ctor(php_cli_server *server, const char *addr, const c
23302318

23312319
if (router) {
23322320
size_t router_len = strlen(router);
2333-
_router = pestrndup(router, router_len, 1);
2334-
if (!_router) {
2335-
retval = FAILURE;
2336-
goto out;
2321+
if (!IS_ABSOLUTE_PATH(router, router_len)) {
2322+
_router = pemalloc(server->document_root_len + router_len + 2, 1);
2323+
if (!_router) {
2324+
retval = FAILURE;
2325+
goto out;
2326+
}
2327+
snprintf(_router,
2328+
server->document_root_len + router_len + 2, "%s%c%s", server->document_root, DEFAULT_SLASH, router);
2329+
} else {
2330+
_router = pestrndup(router, router_len, 1);
2331+
if (!_router) {
2332+
retval = FAILURE;
2333+
goto out;
2334+
}
23372335
}
23382336
server->router = _router;
23392337
server->router_len = router_len;

0 commit comments

Comments
 (0)