Skip to content
Merged
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 NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ PHP NEWS
- GD:
. Fix incorrect comparison with result of php_stream_can_cast(). (Girgias)

- Intl:
. Fix return value on failure for resourcebundle count handler. (Girgias)


- OPcache:
. Disallow changing opcache.memory_consumption when SHM is already set up.
(timwolla)
Expand All @@ -28,6 +32,10 @@ PHP NEWS
. Add $digest_algo parameter to openssl_public_encrypt() and
openssl_private_decrypt() functions. (Jakub Zelenka)

- POSIX:
. posix_kill and posix_setpgid throws a ValueError on invalid process_id.
(David Carlier)

- Reflection:
. Fixed bug GH-19187 (ReflectionNamedType::getName() prints nullable type when
retrieved from ReflectionProperty::getSettableType()). (ilutov)
Expand Down
4 changes: 4 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,10 @@ PHP 8.5 UPGRADE NOTES
an invalid file descriptor.
. posix_fpathconf checks invalid file descriptors and sets
last_error to EBADF and raises an E_WARNING message.
. posix_kill throws a ValueError when the process_id argument is lower
or greater than what supports the platform (signed integer or long
range), posix_setpgid throws a ValueError when the process_id is
lower than zero or greater than what supports the platform.

- Reflection:
. The output of ReflectionClass::toString() for enums has changed to
Expand Down
2 changes: 1 addition & 1 deletion ext/intl/resourcebundle/resourcebundle_class.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ static zend_result resourcebundle_array_count(zend_object *object, zend_long *co
if (rb->me == NULL) {
intl_errors_set(&rb->error, U_ILLEGAL_ARGUMENT_ERROR,
"Found unconstructed ResourceBundle", 0);
return 0;
return FAILURE;
}

*count = ures_getSize( rb->me );
Expand Down
18 changes: 18 additions & 0 deletions ext/posix/posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@
# include <sys/sysmacros.h>
#endif

#if (defined(__sun) && !defined(_LP64)) || defined(_AIX)
#define POSIX_PID_MIN LONG_MIN
#define POSIX_PID_MAX LONG_MAX
#else
#define POSIX_PID_MIN INT_MIN
#define POSIX_PID_MAX INT_MAX
#endif

#include "posix_arginfo.h"

ZEND_DECLARE_MODULE_GLOBALS(posix)
Expand Down Expand Up @@ -118,6 +126,12 @@ ZEND_GET_MODULE(posix)
} \
RETURN_TRUE;

#define PHP_POSIX_CHECK_PID(pid, lower, upper) \
if (pid < lower || pid > upper) { \
zend_argument_value_error(1, "must be between " ZEND_LONG_FMT " and " ZEND_LONG_FMT, lower, upper); \
RETURN_THROWS(); \
}

/* {{{ Send a signal to a process (POSIX.1, 3.3.2) */

PHP_FUNCTION(posix_kill)
Expand All @@ -129,6 +143,8 @@ PHP_FUNCTION(posix_kill)
Z_PARAM_LONG(sig)
ZEND_PARSE_PARAMETERS_END();

PHP_POSIX_CHECK_PID(pid, POSIX_PID_MIN, POSIX_PID_MAX)

if (kill(pid, sig) < 0) {
POSIX_G(last_error) = errno;
RETURN_FALSE;
Expand Down Expand Up @@ -291,6 +307,8 @@ PHP_FUNCTION(posix_setpgid)
Z_PARAM_LONG(pgid)
ZEND_PARSE_PARAMETERS_END();

PHP_POSIX_CHECK_PID(pid, 0, POSIX_PID_MAX)

if (setpgid(pid, pgid) < 0) {
POSIX_G(last_error) = errno;
RETURN_FALSE;
Expand Down
24 changes: 24 additions & 0 deletions ext/posix/tests/posix_kill_pidoverflow.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--TEST--
posix_kill() with large pid
--EXTENSIONS--
posix
--SKIPIF--
<?php if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only"); ?>
--FILE--
<?php
// with pid overflow, it ends up being -1 which means all permissible processes are affected
try {
posix_kill(PHP_INT_MAX, SIGTERM);
} catch (\ValueError $e) {
echo $e->getMessage(), PHP_EOL;
}

try {
posix_kill(PHP_INT_MIN, SIGTERM);
} catch (\ValueError $e) {
echo $e->getMessage(), PHP_EOL;
}
?>
--EXPECTF--
posix_kill(): Argument #1 ($process_id) must be between %i and %d
posix_kill(): Argument #1 ($process_id) must be between %i and %d
22 changes: 22 additions & 0 deletions ext/posix/tests/posix_setpgid_error.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--TEST--
posix_setpgid() with wrong pid values
--EXTENSIONS--
posix
--SKIPIF--
<?php if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only"); ?>
--FILE--
<?php
try {
posix_setpgid(PHP_INT_MAX, 1);
} catch (\ValueError $e) {
echo $e->getMessage(), PHP_EOL;
}
try {
posix_setpgid(-2, 1);
} catch (\ValueError $e) {
echo $e->getMessage(), PHP_EOL;
}
?>
--EXPECTF--
posix_setpgid(): Argument #1 ($process_id) must be between 0 and %d
posix_setpgid(): Argument #1 ($process_id) must be between 0 and %d
65 changes: 27 additions & 38 deletions ext/sysvmsg/sysvmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,32 +127,32 @@ PHP_MINFO_FUNCTION(sysvmsg)
/* {{{ Set information for a message queue */
PHP_FUNCTION(msg_set_queue)
{
zval *queue, *data;
zval *queue;
HashTable *data;
sysvmsg_queue_t *mq = NULL;
struct msqid_ds stat;

RETVAL_FALSE;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "Oa", &queue, sysvmsg_queue_ce, &data) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Oh", &queue, sysvmsg_queue_ce, &data) == FAILURE) {
RETURN_THROWS();
}

mq = Z_SYSVMSG_QUEUE_P(queue);

RETVAL_FALSE;
if (msgctl(mq->id, IPC_STAT, &stat) == 0) {
zval *item;

/* now pull out members of data and set them in the stat buffer */
if ((item = zend_hash_str_find(Z_ARRVAL_P(data), "msg_perm.uid", sizeof("msg_perm.uid") - 1)) != NULL) {
if ((item = zend_hash_str_find(data, ZEND_STRL("msg_perm.uid"))) != NULL) {
stat.msg_perm.uid = zval_get_long(item);
}
if ((item = zend_hash_str_find(Z_ARRVAL_P(data), "msg_perm.gid", sizeof("msg_perm.gid") - 1)) != NULL) {
if ((item = zend_hash_str_find(data, ZEND_STRL("msg_perm.gid"))) != NULL) {
stat.msg_perm.gid = zval_get_long(item);
}
if ((item = zend_hash_str_find(Z_ARRVAL_P(data), "msg_perm.mode", sizeof("msg_perm.mode") - 1)) != NULL) {
if ((item = zend_hash_str_find(data, ZEND_STRL("msg_perm.mode"))) != NULL) {
stat.msg_perm.mode = zval_get_long(item);
}
if ((item = zend_hash_str_find(Z_ARRVAL_P(data), "msg_qbytes", sizeof("msg_qbytes") - 1)) != NULL) {
if ((item = zend_hash_str_find(data, ZEND_STRL("msg_qbytes"))) != NULL) {
stat.msg_qbytes = zval_get_long(item);
}
if (msgctl(mq->id, IPC_SET, &stat) == 0) {
Expand All @@ -169,28 +169,27 @@ PHP_FUNCTION(msg_stat_queue)
sysvmsg_queue_t *mq = NULL;
struct msqid_ds stat;

RETVAL_FALSE;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &queue, sysvmsg_queue_ce) == FAILURE) {
RETURN_THROWS();
}

mq = Z_SYSVMSG_QUEUE_P(queue);

if (msgctl(mq->id, IPC_STAT, &stat) == 0) {
array_init(return_value);

add_assoc_long(return_value, "msg_perm.uid", stat.msg_perm.uid);
add_assoc_long(return_value, "msg_perm.gid", stat.msg_perm.gid);
add_assoc_long(return_value, "msg_perm.mode", stat.msg_perm.mode);
add_assoc_long(return_value, "msg_stime", stat.msg_stime);
add_assoc_long(return_value, "msg_rtime", stat.msg_rtime);
add_assoc_long(return_value, "msg_ctime", stat.msg_ctime);
add_assoc_long(return_value, "msg_qnum", stat.msg_qnum);
add_assoc_long(return_value, "msg_qbytes", stat.msg_qbytes);
add_assoc_long(return_value, "msg_lspid", stat.msg_lspid);
add_assoc_long(return_value, "msg_lrpid", stat.msg_lrpid);
if (msgctl(mq->id, IPC_STAT, &stat) != 0) {
RETURN_FALSE;
}

array_init_size(return_value, 10);
add_assoc_long(return_value, "msg_perm.uid", stat.msg_perm.uid);
add_assoc_long(return_value, "msg_perm.gid", stat.msg_perm.gid);
add_assoc_long(return_value, "msg_perm.mode", stat.msg_perm.mode);
add_assoc_long(return_value, "msg_stime", stat.msg_stime);
add_assoc_long(return_value, "msg_rtime", stat.msg_rtime);
add_assoc_long(return_value, "msg_ctime", stat.msg_ctime);
add_assoc_long(return_value, "msg_qnum", stat.msg_qnum);
add_assoc_long(return_value, "msg_qbytes", stat.msg_qbytes);
add_assoc_long(return_value, "msg_lspid", stat.msg_lspid);
add_assoc_long(return_value, "msg_lrpid", stat.msg_lrpid);
}
/* }}} */

Expand All @@ -203,11 +202,7 @@ PHP_FUNCTION(msg_queue_exists)
RETURN_THROWS();
}

if (msgget(key, 0) < 0) {
RETURN_FALSE;
}

RETURN_TRUE;
RETURN_BOOL(msgget(key, 0) >= 0);
}
/* }}} */

Expand Down Expand Up @@ -251,11 +246,7 @@ PHP_FUNCTION(msg_remove_queue)

mq = Z_SYSVMSG_QUEUE_P(queue);

if (msgctl(mq->id, IPC_RMID, NULL) == 0) {
RETVAL_TRUE;
} else {
RETVAL_FALSE;
}
RETURN_BOOL(msgctl(mq->id, IPC_RMID, NULL) == 0);
}
/* }}} */

Expand All @@ -270,8 +261,6 @@ PHP_FUNCTION(msg_receive)
struct php_msgbuf *messagebuffer = NULL; /* buffer to transmit */
int result;

RETVAL_FALSE;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "Olzlz|blz",
&queue, sysvmsg_queue_ce, &desiredmsgtype, &out_msgtype, &maxsize,
&out_message, &do_unserialize, &flags, &zerrcode) == FAILURE) {
Expand Down Expand Up @@ -337,6 +326,7 @@ PHP_FUNCTION(msg_receive)
if (zerrcode) {
ZEND_TRY_ASSIGN_REF_LONG(zerrcode, errno);
}
RETVAL_FALSE;
}
efree(messagebuffer);
}
Expand All @@ -353,8 +343,6 @@ PHP_FUNCTION(msg_send)
int result;
size_t message_len = 0;

RETVAL_FALSE;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "Olz|bbz",
&queue, sysvmsg_queue_ce, &msgtype, &message, &do_serialize, &blocking, &zerror) == FAILURE) {
RETURN_THROWS();
Expand Down Expand Up @@ -429,8 +417,9 @@ PHP_FUNCTION(msg_send)
if (zerror) {
ZEND_TRY_ASSIGN_REF_LONG(zerror, errno);
}
RETURN_FALSE;
} else {
RETVAL_TRUE;
RETURN_TRUE;
}
}
/* }}} */
6 changes: 3 additions & 3 deletions ext/sysvsem/sysvsem.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ PHP_FUNCTION(sem_get)
/* }}} */

/* {{{ php_sysvsem_semop */
static void php_sysvsem_semop(INTERNAL_FUNCTION_PARAMETERS, int acquire)
static void php_sysvsem_semop(INTERNAL_FUNCTION_PARAMETERS, bool acquire)
{
zval *arg_id;
bool nowait = 0;
Expand Down Expand Up @@ -311,14 +311,14 @@ static void php_sysvsem_semop(INTERNAL_FUNCTION_PARAMETERS, int acquire)
/* {{{ Acquires the semaphore with the given id, blocking if necessary */
PHP_FUNCTION(sem_acquire)
{
php_sysvsem_semop(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
php_sysvsem_semop(INTERNAL_FUNCTION_PARAM_PASSTHRU, true);
}
/* }}} */

/* {{{ Releases the semaphore with the given id */
PHP_FUNCTION(sem_release)
{
php_sysvsem_semop(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
php_sysvsem_semop(INTERNAL_FUNCTION_PARAM_PASSTHRU, false);
}
/* }}} */

Expand Down
12 changes: 6 additions & 6 deletions ext/sysvshm/php_sysvshm.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@ typedef struct {

typedef struct {
zend_long key;
zend_long length;
zend_long next;
size_t length;
size_t next;
char mem;
} sysvshm_chunk;

typedef struct {
char magic[8];
zend_long start;
zend_long end;
zend_long free;
zend_long total;
size_t start;
size_t end;
size_t free;
size_t total;
} sysvshm_chunk_head;

typedef struct {
Expand Down
Loading