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: 1 addition & 7 deletions Zend/tests/attributes/nodiscard/005.phpt
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
--TEST--
#[\NoDiscard]: Native function and method.
#[\NoDiscard]: Native method.
--FILE--
<?php

$f = tmpfile();
flock($f, LOCK_SH | LOCK_NB);
fclose($f);

$date = new DateTimeImmutable('now');
$date->setTimestamp(0);

?>
--EXPECTF--
Warning: The return value of function flock() should either be used or intentionally ignored by casting it as (void), as locking the stream might have failed in %s on line %d

Warning: The return value of method DateTimeImmutable::setTimestamp() should either be used or intentionally ignored by casting it as (void), as DateTimeImmutable::setTimestamp() does not modify the object itself in %s on line %d
10 changes: 3 additions & 7 deletions Zend/tests/attributes/nodiscard/007.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,11 @@ zend_test.observer.execute_internal=1
--FILE--
<?php

$f = tmpfile();
flock($f, LOCK_SH | LOCK_NB);
fclose($f);
zend_test_nodiscard();

?>
--EXPECTF--
<!-- internal enter tmpfile() -->
<!-- internal enter NoDiscard::__construct() -->

Warning: The return value of function flock() should either be used or intentionally ignored by casting it as (void), as locking the stream might have failed in %s on line %d
<!-- internal enter flock() -->
<!-- internal enter fclose() -->
Warning: The return value of function zend_test_nodiscard() should either be used or intentionally ignored by casting it as (void), custom message in %s on line %d
<!-- internal enter zend_test_nodiscard() -->
12 changes: 12 additions & 0 deletions Zend/tests/attributes/nodiscard/010.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--TEST--
#[\NoDiscard]: Native function.
--EXTENSIONS--
zend_test
--FILE--
<?php

zend_test_nodiscard();

?>
--EXPECTF--
Warning: The return value of function zend_test_nodiscard() should either be used or intentionally ignored by casting it as (void), custom message in %s on line %d
23 changes: 23 additions & 0 deletions Zend/tests/property_hooks/gh18268.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--TEST--
GH-18268: array_walk() on object with added property hooks
--FILE--
<?php

class A {
public $prop = 42;
}

class B extends A {
public $prop = 42 {
set {}
}
}

$b = new B;
array_walk($b, function (&$item) {
var_dump($item);
});

?>
--EXPECT--
int(42)
2 changes: 2 additions & 0 deletions Zend/zend_compile.h
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,8 @@ typedef struct _zend_property_info {
((uint32_t)(XtOffsetOf(zend_object, properties_table) + sizeof(zval) * (num)))
#define OBJ_PROP_TO_NUM(offset) \
(((offset) - OBJ_PROP_TO_OFFSET(0)) / sizeof(zval))
#define OBJ_PROP_SLOT_TO_OFFSET(obj, slot) \
((uintptr_t)(slot) - (uintptr_t)(obj))

typedef struct _zend_class_constant {
zval value; /* flags are stored in u2 */
Expand Down
2 changes: 1 addition & 1 deletion Zend/zend_objects_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ ZEND_API void ZEND_FASTCALL zend_objects_store_del(zend_object *object) /* {{{ *

ZEND_API ZEND_COLD zend_property_info *zend_get_property_info_for_slot_slow(zend_object *obj, zval *slot)
{
uintptr_t offset = (uintptr_t)slot - (uintptr_t)obj->properties_table;
uintptr_t offset = OBJ_PROP_SLOT_TO_OFFSET(obj, slot);
zend_property_info *prop_info;
ZEND_HASH_MAP_FOREACH_PTR(&obj->ce->properties_info, prop_info) {
if (prop_info->offset == offset) {
Expand Down
59 changes: 23 additions & 36 deletions ext/opcache/tests/nodiscard_001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ opcache.optimization_level=-1
opcache.opt_debug_level=0x20000
--EXTENSIONS--
opcache
zend_test
--FILE--
<?php

$f = tmpfile();
flock($f, LOCK_SH | LOCK_NB);
(void)flock($f, LOCK_SH | LOCK_NB);
$success = flock($f, LOCK_SH | LOCK_NB);
fclose($f);
zend_test_nodiscard();
(void)zend_test_nodiscard();
$success = zend_test_nodiscard();

#[\NoDiscard]
function test() {
Expand All @@ -28,38 +27,26 @@ $obj = test();
?>
--EXPECTF--
$_main:
; (lines=29, args=0, vars=3, tmps=%d)
; (lines=17, args=0, vars=2, tmps=%d)
; (after optimizer)
; %s
0000 INIT_FCALL 0 %d string("tmpfile")
0001 V3 = DO_ICALL
0002 ASSIGN CV0($f) V3
0003 INIT_FCALL 2 %d string("flock")
0004 SEND_VAR CV0($f) 1
0005 SEND_VAL int(5) 2
0006 DO_FCALL_BY_NAME
0007 INIT_FCALL 2 %d string("flock")
0008 SEND_VAR CV0($f) 1
0009 SEND_VAL int(5) 2
0010 V3 = DO_ICALL
0011 FREE V3
0012 INIT_FCALL 2 %d string("flock")
0013 SEND_VAR CV0($f) 1
0014 SEND_VAL int(5) 2
0015 V3 = DO_ICALL
0016 ASSIGN CV1($success) V3
0017 INIT_FCALL 1 %d string("fclose")
0018 SEND_VAR CV0($f) 1
0019 DO_ICALL
0020 INIT_FCALL 0 %d string("test")
0021 DO_FCALL_BY_NAME
0022 INIT_FCALL 0 %d string("test")
0023 V3 = DO_UCALL
0024 FREE V3
0025 INIT_FCALL 0 %d string("test")
0026 V3 = DO_UCALL
0027 ASSIGN CV2($obj) V3
0028 RETURN int(1)
0000 INIT_FCALL 0 %d string("zend_test_nodiscard")
0001 DO_FCALL_BY_NAME
0002 INIT_FCALL 0 %d string("zend_test_nodiscard")
0003 V2 = DO_ICALL
0004 FREE V2
0005 INIT_FCALL 0 %d string("zend_test_nodiscard")
0006 V2 = DO_ICALL
0007 ASSIGN CV0($success) V2
0008 INIT_FCALL 0 %d string("test")
0009 DO_FCALL_BY_NAME
0010 INIT_FCALL 0 %d string("test")
0011 V2 = DO_UCALL
0012 FREE V2
0013 INIT_FCALL 0 %d string("test")
0014 V2 = DO_UCALL
0015 ASSIGN CV1($obj) V2
0016 RETURN int(1)

test:
; (lines=3, args=0, vars=0, tmps=%d)
Expand All @@ -71,6 +58,6 @@ test:
LIVE RANGES:
0: 0001 - 0002 (new)

Warning: The return value of function flock() should either be used or intentionally ignored by casting it as (void), as locking the stream might have failed in %s on line %d
Warning: The return value of function zend_test_nodiscard() should either be used or intentionally ignored by casting it as (void), custom message in %s on line %d

Warning: The return value of function test() should either be used or intentionally ignored by casting it as (void) in %s on line %d
15 changes: 0 additions & 15 deletions ext/openssl/openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -3975,20 +3975,11 @@ PHP_FUNCTION(openssl_sign)

md_ctx = EVP_MD_CTX_create();
size_t siglen;
#if PHP_OPENSSL_API_VERSION >= 0x10100
if (md_ctx != NULL &&
EVP_DigestSignInit(md_ctx, NULL, mdtype, NULL, pkey) &&
EVP_DigestSign(md_ctx, NULL, &siglen, (unsigned char*)data, data_len) &&
(sigbuf = zend_string_alloc(siglen, 0)) != NULL &&
EVP_DigestSign(md_ctx, (unsigned char*)ZSTR_VAL(sigbuf), &siglen, (unsigned char*)data, data_len)) {
#else
if (md_ctx != NULL &&
EVP_SignInit(md_ctx, mdtype) &&
EVP_SignUpdate(md_ctx, data, data_len) &&
(siglen = EVP_PKEY_size(pkey)) &&
(sigbuf = zend_string_alloc(siglen, 0)) != NULL &&
EVP_SignFinal(md_ctx, (unsigned char*)ZSTR_VAL(sigbuf), (unsigned int*)&siglen, pkey)) {
#endif
ZSTR_VAL(sigbuf)[siglen] = '\0';
ZSTR_LEN(sigbuf) = siglen;
ZEND_TRY_ASSIGN_REF_NEW_STR(signature, sigbuf);
Expand Down Expand Up @@ -4049,14 +4040,8 @@ PHP_FUNCTION(openssl_verify)

md_ctx = EVP_MD_CTX_create();
if (md_ctx == NULL ||
#if PHP_OPENSSL_API_VERSION >= 0x10100
!EVP_DigestVerifyInit(md_ctx, NULL, mdtype, NULL, pkey) ||
(err = EVP_DigestVerify(md_ctx, (unsigned char *)signature, signature_len, (unsigned char*)data, data_len)) < 0) {
#else
!EVP_VerifyInit (md_ctx, mdtype) ||
!EVP_VerifyUpdate (md_ctx, data, data_len) ||
(err = EVP_VerifyFinal(md_ctx, (unsigned char *)signature, (unsigned int)signature_len, pkey)) < 0) {
#endif
php_openssl_store_errors();
}
EVP_MD_CTX_destroy(md_ctx);
Expand Down
8 changes: 0 additions & 8 deletions ext/openssl/openssl.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,6 @@
*/
const OPENSSL_ALGO_MD2 = UNKNOWN;
#endif
#if PHP_OPENSSL_API_VERSION < 0x10100
/**
* @var int
* @cvalue OPENSSL_ALGO_DSS1
*/
const OPENSSL_ALGO_DSS1 = UNKNOWN;
#endif

/**
* @var int
* @cvalue OPENSSL_ALGO_SHA224
Expand Down
5 changes: 1 addition & 4 deletions ext/openssl/openssl_arginfo.h

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

39 changes: 4 additions & 35 deletions ext/openssl/openssl_backend_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,6 @@ zend_result php_openssl_write_rand_file(const char * file, int egdsocket, int se
if (file == NULL) {
file = RAND_file_name(buffer, sizeof(buffer));
}
PHP_OPENSSL_RAND_ADD_TIME();
if (file == NULL || !RAND_write_file(file)) {
php_openssl_store_errors();
php_error_docref(NULL, E_WARNING, "Unable to write random state");
Expand Down Expand Up @@ -489,11 +488,6 @@ EVP_MD * php_openssl_get_evp_md_from_algo(zend_long algo) {
case OPENSSL_ALGO_MD2:
mdtype = (EVP_MD *) EVP_md2();
break;
#endif
#if PHP_OPENSSL_API_VERSION < 0x10100
case OPENSSL_ALGO_DSS1:
mdtype = (EVP_MD *) EVP_dss1();
break;
#endif
case OPENSSL_ALGO_SHA224:
mdtype = (EVP_MD *) EVP_sha224();
Expand Down Expand Up @@ -1510,7 +1504,6 @@ EVP_PKEY * php_openssl_generate_private_key(struct php_x509_request * req)
int egdsocket, seeded;
char *randfile = php_openssl_conf_get_string(req->req_config, req->section_name, "RANDFILE");
php_openssl_load_rand_file(randfile, &egdsocket, &seeded);
PHP_OPENSSL_RAND_ADD_TIME();

EVP_PKEY *key = NULL;
EVP_PKEY *params = NULL;
Expand Down Expand Up @@ -1700,48 +1693,25 @@ void php_openssl_load_cipher_mode(struct php_openssl_cipher_mode *mode, const EV
int cipher_mode = EVP_CIPHER_mode(cipher_type);
memset(mode, 0, sizeof(struct php_openssl_cipher_mode));
switch (cipher_mode) {
#if PHP_OPENSSL_API_VERSION >= 0x10100
/* Since OpenSSL 1.1, all AEAD ciphers use a common framework. We check for
* EVP_CIPH_OCB_MODE, because LibreSSL does not support it. */
case EVP_CIPH_GCM_MODE:
case EVP_CIPH_CCM_MODE:
# ifdef EVP_CIPH_OCB_MODE
/* We check for EVP_CIPH_OCB_MODE, because LibreSSL does not support it. */
#ifdef EVP_CIPH_OCB_MODE
case EVP_CIPH_OCB_MODE:
/* For OCB mode, explicitly set the tag length even when decrypting,
* see https://github.com/openssl/openssl/issues/8331. */
mode->set_tag_length_always = cipher_mode == EVP_CIPH_OCB_MODE;
# endif
#endif
php_openssl_set_aead_flags(mode);
mode->set_tag_length_when_encrypting = cipher_mode == EVP_CIPH_CCM_MODE;
mode->is_single_run_aead = cipher_mode == EVP_CIPH_CCM_MODE;
break;
# ifdef NID_chacha20_poly1305
#ifdef NID_chacha20_poly1305
default:
if (EVP_CIPHER_nid(cipher_type) == NID_chacha20_poly1305) {
php_openssl_set_aead_flags(mode);
}
break;

# endif
#else
# ifdef EVP_CIPH_GCM_MODE
case EVP_CIPH_GCM_MODE:
mode->is_aead = 1;
mode->aead_get_tag_flag = EVP_CTRL_GCM_GET_TAG;
mode->aead_set_tag_flag = EVP_CTRL_GCM_SET_TAG;
mode->aead_ivlen_flag = EVP_CTRL_GCM_SET_IVLEN;
break;
# endif
# ifdef EVP_CIPH_CCM_MODE
case EVP_CIPH_CCM_MODE:
mode->is_aead = 1;
mode->is_single_run_aead = 1;
mode->set_tag_length_when_encrypting = 1;
mode->aead_get_tag_flag = EVP_CTRL_CCM_GET_TAG;
mode->aead_set_tag_flag = EVP_CTRL_CCM_SET_TAG;
mode->aead_ivlen_flag = EVP_CTRL_CCM_SET_IVLEN;
break;
# endif
#endif
}
}
Expand Down Expand Up @@ -2121,7 +2091,6 @@ PHP_OPENSSL_API zend_string* php_openssl_random_pseudo_bytes(zend_long buffer_le
buffer = zend_string_alloc(buffer_length, 0);

PHP_OPENSSL_CHECK_LONG_TO_INT_NULL_RETURN(buffer_length, length);
PHP_OPENSSL_RAND_ADD_TIME();
if (RAND_bytes((unsigned char*)ZSTR_VAL(buffer), (int)buffer_length) <= 0) {
php_openssl_store_errors();
zend_string_release_ex(buffer, 0);
Expand Down
3 changes: 0 additions & 3 deletions ext/openssl/openssl_backend_v1.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ static bool php_openssl_pkey_init_dsa_data(DSA *dsa, zval *data, bool *is_privat
}

/* generate key */
PHP_OPENSSL_RAND_ADD_TIME();
if (!DSA_generate_key(dsa)) {
php_openssl_store_errors();
return 0;
Expand Down Expand Up @@ -185,7 +184,6 @@ static bool php_openssl_pkey_init_dh_data(DH *dh, zval *data, bool *is_private)
}

/* generate key */
PHP_OPENSSL_RAND_ADD_TIME();
if (!DH_generate_key(dh)) {
php_openssl_store_errors();
return 0;
Expand Down Expand Up @@ -341,7 +339,6 @@ static bool php_openssl_pkey_init_ec_data(EC_KEY *eckey, zval *data, bool *is_pr

if (!EC_KEY_check_key(eckey)) {
*is_private = true;
PHP_OPENSSL_RAND_ADD_TIME();
EC_KEY_generate_key(eckey);
}

Expand Down
4 changes: 0 additions & 4 deletions ext/openssl/openssl_backend_v3.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ EVP_PKEY *php_openssl_pkey_init_dsa(zval *data, bool *is_private)
pkey = param_key;
} else {
*is_private = true;
PHP_OPENSSL_RAND_ADD_TIME();
EVP_PKEY_CTX_free(ctx);
ctx = EVP_PKEY_CTX_new(param_key, NULL);
if (EVP_PKEY_keygen_init(ctx) <= 0 || EVP_PKEY_keygen(ctx, &pkey) <= 0) {
Expand Down Expand Up @@ -219,7 +218,6 @@ EVP_PKEY *php_openssl_pkey_init_dh(zval *data, bool *is_private)
pkey = param_key;
} else {
*is_private = true;
PHP_OPENSSL_RAND_ADD_TIME();
EVP_PKEY_CTX_free(ctx);
ctx = EVP_PKEY_CTX_new(param_key, NULL);
if (EVP_PKEY_keygen_init(ctx) <= 0 || EVP_PKEY_keygen(ctx, &pkey) <= 0) {
Expand Down Expand Up @@ -407,7 +405,6 @@ EVP_PKEY *php_openssl_pkey_init_ec(zval *data, bool *is_private) {
pkey = param_key;
} else {
*is_private = true;
PHP_OPENSSL_RAND_ADD_TIME();
if (EVP_PKEY_keygen_init(ctx) != 1 ||
EVP_PKEY_CTX_set_params(ctx, params) != 1 ||
EVP_PKEY_generate(ctx, &pkey) != 1) {
Expand Down Expand Up @@ -482,7 +479,6 @@ void php_openssl_pkey_object_curve_25519_448(zval *return_value, int key_type, z
is_private = priv_key != NULL;
} else {
is_private = true;
PHP_OPENSSL_RAND_ADD_TIME();
if (EVP_PKEY_keygen_init(ctx) <= 0 || EVP_PKEY_keygen(ctx, &pkey) <= 0) {
goto cleanup;
}
Expand Down
Loading
Loading