Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Zend/zend_exceptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ ZEND_API zend_class_entry *zend_ce_value_error;
ZEND_API zend_class_entry *zend_ce_arithmetic_error;
ZEND_API zend_class_entry *zend_ce_division_by_zero_error;
ZEND_API zend_class_entry *zend_ce_unhandled_match_error;
ZEND_API zend_class_entry *zend_ce_access_error;
ZEND_API zend_class_entry *zend_ce_openbasedir_access_error;
ZEND_API zend_class_entry *zend_ce_request_parse_body_exception;

/* Internal pseudo-exception that is not exposed to userland. Throwing this exception *does not* execute finally blocks. */
Expand Down Expand Up @@ -788,6 +790,12 @@ void zend_register_default_exception(void) /* {{{ */
zend_ce_unhandled_match_error = register_class_UnhandledMatchError(zend_ce_error);
zend_init_exception_class_entry(zend_ce_unhandled_match_error);

zend_ce_access_error = register_class_AccessError(zend_ce_error);
zend_init_exception_class_entry(zend_ce_access_error);

zend_ce_openbasedir_access_error = register_class_OpenbasedirAccessError(zend_ce_access_error);
zend_init_exception_class_entry(zend_ce_openbasedir_access_error);

zend_ce_request_parse_body_exception = register_class_RequestParseBodyException(zend_ce_exception);
zend_init_exception_class_entry(zend_ce_request_parse_body_exception);

Expand Down
2 changes: 2 additions & 0 deletions Zend/zend_exceptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ extern ZEND_API zend_class_entry *zend_ce_value_error;
extern ZEND_API zend_class_entry *zend_ce_arithmetic_error;
extern ZEND_API zend_class_entry *zend_ce_division_by_zero_error;
extern ZEND_API zend_class_entry *zend_ce_unhandled_match_error;
extern ZEND_API zend_class_entry *zend_ce_access_error;
extern ZEND_API zend_class_entry *zend_ce_openbasedir_access_error;
extern ZEND_API zend_class_entry *zend_ce_request_parse_body_exception;

ZEND_API void zend_exception_set_previous(zend_object *exception, zend_object *add_previous);
Expand Down
8 changes: 8 additions & 0 deletions Zend/zend_exceptions.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,14 @@ class UnhandledMatchError extends Error
{
}

class AccessError extends Error
{
}

class OpenbasedirAccessError extends AccessError
{
}

class RequestParseBodyException extends Exception
{
}
30 changes: 29 additions & 1 deletion Zend/zend_exceptions_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions ext/pcntl/pcntl.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "php_pcntl.h"
#include "php_signal.h"
#include "php_ticks.h"
#include "zend_exceptions.h"
#include "zend_fibers.h"

#if defined(HAVE_GETPRIORITY) || defined(HAVE_SETPRIORITY) || defined(HAVE_WAIT3)
Expand Down Expand Up @@ -599,6 +600,12 @@ PHP_FUNCTION(pcntl_exec)
Z_PARAM_ARRAY(envs)
ZEND_PARSE_PARAMETERS_END();

if (php_check_open_basedir_ex(path, 0)) {
// TODO we may generalise the following with a new handy specialised call
zend_argument_error(zend_ce_openbasedir_access_error, 1, "open_basedir restriction in effect for the path `%s`.", path);
RETURN_THROWS();
}

if (ZEND_NUM_ARGS() > 1) {
/* Build argument list */
SEPARATE_ARRAY(args);
Expand Down
21 changes: 21 additions & 0 deletions ext/pcntl/tests/pcntl_exec_restrict.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--TEST--
pcntl_exec() - Testing with open_basedir restriction.
--EXTENSIONS--
pcntl
--INI--
open_basedir=${HOME}/authorizedbins
--SKIPIF--
<?php
if (!getenv("TEST_PHP_EXECUTABLE") || !is_executable(getenv("TEST_PHP_EXECUTABLE"))) die("skip TEST_PHP_EXECUTABLE not set");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although not likely, $TEST_PHP_EXECUTABLE might be under $HOME/bin.

Perhaps ensure that test will always be correct regardless of environment it runs in.

?>
--FILE--
<?php
try {
pcntl_exec(getenv("TEST_PHP_EXECUTABLE"), ['-n', new stdClass()]);
} catch (OpenbasedirAccessError $error) {
echo $error->getMessage();
}

?>
--EXPECTF--
pcntl_exec(): Argument #1 ($path) open_basedir restriction in effect for the path `%s`.