33#ifdef HAVE_SYS_TYPES_H
53static size_t cmd_max_len;
59 cmd_max_len = sysconf(_SC_ARG_MAX);
60 if ((
size_t)-1 == cmd_max_len) {
62 cmd_max_len = _POSIX_ARG_MAX;
68 cmd_max_len = ARG_MAX;
69#elif defined(PHP_WIN32)
82static size_t strip_trailing_whitespace(
char *
buf,
size_t bufl) {
84 while (l-- > 0 && isspace(((
unsigned char *)
buf)[l]));
85 if (l != (bufl - 1)) {
92static size_t handle_line(
int type,
zval *array,
char *
buf,
size_t bufl) {
98 }
else if (
type == 2) {
99 bufl = strip_trailing_whitespace(
buf, bufl);
119 size_t buflen, bufl = 0;
158 }
else if (b !=
buf) {
162 bufl = handle_line(
type, array,
buf, bufl);
168 bufl = handle_line(
type, array,
buf, bufl);
172 bufl = strip_trailing_whitespace(
buf, bufl);
196 return pclose_return;
224 if (
strlen(cmd) != cmd_len) {
236 ret_array = zend_try_array_init(ret_array);
290 const char *str =
ZSTR_VAL(unescaped_cmd);
292 uint64_t estimate = (2 * (uint64_t)l) + 1;
295 if (l > cmd_max_len - 2 - 1) {
296 zend_value_error(
"Command exceeds the allowed length of %zu bytes", cmd_max_len);
300 cmd = zend_string_safe_alloc(2, l, 0, 0);
302 for (x = 0, y = 0; x < l; x++) {
303 int mb_len =
php_mblen(str + x, (l - x));
308 }
else if (mb_len > 1) {
319 if (!
p && (
p = memchr(str + x + 1, str[x], l - x - 1))) {
321 }
else if (
p && *
p == str[x]) {
371 if (y > cmd_max_len + 1) {
372 zend_value_error(
"Escaped command exceeds the allowed length of %zu bytes", cmd_max_len);
377 if ((estimate - y) > 4096) {
380 cmd = zend_string_truncate(cmd, y, 0);
397 const char *str =
ZSTR_VAL(unescaped_arg);
399 uint64_t estimate = (4 * (uint64_t)l) + 3;
402 if (l > cmd_max_len - 2 - 1) {
403 zend_value_error(
"Argument exceeds the allowed length of %zu bytes", cmd_max_len);
407 cmd = zend_string_safe_alloc(4, l, 2, 0);
415 for (x = 0; x < l; x++) {
416 int mb_len =
php_mblen(str + x, (l - x));
421 }
else if (mb_len > 1) {
447 if (y > 0 &&
'\\' ==
ZSTR_VAL(cmd)[y - 1]) {
448 int k = 0,
n = y - 1;
449 for (;
n >= 0 &&
'\\' ==
ZSTR_VAL(cmd)[
n];
n--, k++);
461 if (y > cmd_max_len + 1) {
462 zend_value_error(
"Escaped argument exceeds the allowed length of %zu bytes", cmd_max_len);
467 if ((estimate - y) > 4096) {
470 cmd = zend_string_truncate(cmd, y, 0);
SAPI_API int sapi_flush(void)
escapeshellcmd(string $command)
passthru(string $command, &$result_code=null)
shell_exec(string $command)
escapeshellarg(string $arg)
system(string $command, &$result_code=null)
PHPAPI int php_exec(int type, const char *cmd, zval *array, zval *return_value)
PHPAPI zend_string * php_escape_shell_cmd(const zend_string *unescaped_cmd)
PHPAPI zend_string * php_escape_shell_arg(const zend_string *unescaped_arg)
zend_ffi_ctype_name_buf buf
PHPAPI ZEND_COLD void php_error_docref(const char *docref, int type, const char *format,...)
PHPAPI int nice(zend_long p)
PHPAPI int php_output_get_level(void)
#define PHP_MINIT_FUNCTION
#define php_ignore_value(x)
#define PHPWRITE(str, str_len)
#define php_stream_fopen_from_pipe(file, mode)
struct _php_stream php_stream
#define php_stream_read(stream, buf, count)
#define php_stream_get_line(stream, buf, maxlen, retlen)
#define PHP_STREAM_COPY_ALL
#define php_stream_eof(stream)
#define php_stream_close(stream)
#define php_stream_copy_to_mem(src, maxlen, persistent)
#define php_mblen(ptr, len)
#define php_win_err_free(err)
ZEND_API ZEND_COLD void zend_value_error(const char *format,...)
#define INTERNAL_FUNCTION_PARAMETERS
#define INTERNAL_FUNCTION_PARAM_PASSTHRU
ZEND_API zend_result add_next_index_stringl(zval *arg, const char *str, size_t length)
ZEND_API ZEND_COLD void zend_argument_must_not_be_empty_error(uint32_t arg_num)
ZEND_API ZEND_COLD void zend_argument_value_error(uint32_t arg_num, const char *format,...)
#define Z_PARAM_PATH_STR(dest)
#define ZEND_PARSE_PARAMETERS_END()
#define Z_PARAM_STRING(dest, dest_len)
#define ZEND_PARSE_PARAMETERS_START(min_num_args, max_num_args)
#define RETVAL_EMPTY_STRING()
#define ZEND_TRY_ASSIGN_REF_LONG(zv, lval)
#define Z_PARAM_LONG(dest)
#define Z_PARAM_PATH(dest, dest_len)
#define Z_PARAM_ZVAL(dest)
#define RETVAL_STRINGL(s, l)
#define erealloc(ptr, size)
zend_string_release_ex(func->internal_function.function_name, 0)
ZEND_API void(ZEND_FASTCALL *zend_touch_vm_stack_data)(void *vm_stack_data)
struct _zend_string zend_string
#define ZSTR_EMPTY_ALLOC()
#define Z_REFVAL_P(zval_p)
#define SEPARATE_ARRAY(zv)
#define VCWD_POPEN(command, type)