Skip to content

Commit

Permalink
Fixed bug #75287 (Builtin webserver crash after chdir in a shutdown f…
Browse files Browse the repository at this point in the history
…unction)
  • Loading branch information
laruence committed Oct 15, 2017
1 parent 397f5cb commit 816758e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ PHP NEWS
. Fixed bug #75368 (mmap/munmap trashing on unlucky allocations). (Nikita,
Dmitry)

- CLI:
. Fixed bug #75287 (Builtin webserver crash after chdir in a shutdown
function). (Laruence)

- Exif:
. Fixed bug #75301 (Exif extension has built in revision version). (Peter
Kokot)
Expand Down
30 changes: 14 additions & 16 deletions sapi/cli/php_cli_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -2106,12 +2106,6 @@ static int php_cli_server_dispatch_router(php_cli_server *server, php_cli_server
{
int decline = 0;
zend_file_handle zfd;
char *old_cwd;

ALLOCA_FLAG(use_heap)
old_cwd = do_alloca(MAXPATHLEN, use_heap);
old_cwd[0] = '\0';
php_ignore_value(VCWD_GETCWD(old_cwd, MAXPATHLEN - 1));

zfd.type = ZEND_HANDLE_FILENAME;
zfd.filename = server->router;
Expand All @@ -2133,12 +2127,6 @@ static int php_cli_server_dispatch_router(php_cli_server *server, php_cli_server
}
} zend_end_try();

if (old_cwd[0] != '\0') {
php_ignore_value(VCWD_CHDIR(old_cwd));
}

free_alloca(old_cwd, use_heap);

return decline;
}
/* }}} */
Expand Down Expand Up @@ -2330,10 +2318,20 @@ static int php_cli_server_ctor(php_cli_server *server, const char *addr, const c

if (router) {
size_t router_len = strlen(router);
_router = pestrndup(router, router_len, 1);
if (!_router) {
retval = FAILURE;
goto out;
if (!IS_ABSOLUTE_PATH(router, router_len)) {
_router = pemalloc(server->document_root_len + router_len + 2, 1);
if (!_router) {
retval = FAILURE;
goto out;
}
snprintf(_router,
server->document_root_len + router_len + 2, "%s%c%s", server->document_root, DEFAULT_SLASH, router);
} else {
_router = pestrndup(router, router_len, 1);
if (!_router) {
retval = FAILURE;
goto out;
}
}
server->router = _router;
server->router_len = router_len;
Expand Down

0 comments on commit 816758e

Please sign in to comment.