From ceb16ba6631a8bde4cbde602b1bd988a2741a07d Mon Sep 17 00:00:00 2001 From: lacatoire Date: Tue, 18 Aug 2026 08:17:51 +0200 Subject: [PATCH 1/2] ext/sodium: name the real parameter in the length-mismatch errors sodium_add(), sodium_memcmp() and sodium_compare() all cross-reference their second argument as $string_2, a name none of them declares; the stub calls it $string2. --- ext/sodium/libsodium.c | 6 ++-- .../tests/sodium_length_mismatch_error.phpt | 31 +++++++++++++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 ext/sodium/tests/sodium_length_mismatch_error.phpt diff --git a/ext/sodium/libsodium.c b/ext/sodium/libsodium.c index 8c85991150b5..7b8f41f2f4bb 100644 --- a/ext/sodium/libsodium.c +++ b/ext/sodium/libsodium.c @@ -257,7 +257,7 @@ PHP_FUNCTION(sodium_add) val = (unsigned char *) Z_STRVAL(*val_zv); val_len = Z_STRLEN(*val_zv); if (val_len != addv_len) { - zend_argument_error(sodium_exception_ce, 1, "and argument #2 ($string_2) must have the same length"); + zend_argument_error(sodium_exception_ce, 1, "and argument #2 ($string2) must have the same length"); RETURN_THROWS(); } sodium_add(val, addv, val_len); @@ -277,7 +277,7 @@ PHP_FUNCTION(sodium_memcmp) RETURN_THROWS(); } if (len1 != len2) { - zend_argument_error(sodium_exception_ce, 1, "and argument #2 ($string_2) must have the same length"); + zend_argument_error(sodium_exception_ce, 1, "and argument #2 ($string2) must have the same length"); RETURN_THROWS(); } RETURN_LONG(sodium_memcmp(buf1, buf2, len1)); @@ -3038,7 +3038,7 @@ PHP_FUNCTION(sodium_compare) RETURN_THROWS(); } if (len1 != len2) { - zend_argument_error(sodium_exception_ce, 1, "and argument #2 ($string_2) must have the same length"); + zend_argument_error(sodium_exception_ce, 1, "and argument #2 ($string2) must have the same length"); RETURN_THROWS(); } else { RETURN_LONG(sodium_compare((const unsigned char *) buf1, diff --git a/ext/sodium/tests/sodium_length_mismatch_error.phpt b/ext/sodium/tests/sodium_length_mismatch_error.phpt new file mode 100644 index 000000000000..1a388d5f0d7b --- /dev/null +++ b/ext/sodium/tests/sodium_length_mismatch_error.phpt @@ -0,0 +1,31 @@ +--TEST-- +The length-mismatch errors name the real second parameter +--EXTENSIONS-- +sodium +--FILE-- +getMessage(), "\n"; + } +} + +/* the messages name argument #2, so that name has to be the real one */ +foreach ((new ReflectionFunction('sodium_add'))->getParameters() as $parameter) { + echo '$', $parameter->getName(), "\n"; +} + +?> +--EXPECT-- +sodium_add(): Argument #1 ($string1) and argument #2 ($string2) must have the same length +sodium_memcmp(): Argument #1 ($string1) and argument #2 ($string2) must have the same length +sodium_compare(): Argument #1 ($string1) and argument #2 ($string2) must have the same length +$string1 +$string2 From 4ad1bbccdcad02408e4cc8f2dc7a5d4826d46e6e Mon Sep 17 00:00:00 2001 From: Louis-Arnaud Date: Thu, 20 Aug 2026 23:10:24 +0200 Subject: [PATCH 2/2] Update ext/sodium/tests/sodium_length_mismatch_error.phpt Co-authored-by: NickSdot <32384907+NickSdot@users.noreply.github.com> --- ext/sodium/tests/sodium_length_mismatch_error.phpt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ext/sodium/tests/sodium_length_mismatch_error.phpt b/ext/sodium/tests/sodium_length_mismatch_error.phpt index 1a388d5f0d7b..098f309f5dab 100644 --- a/ext/sodium/tests/sodium_length_mismatch_error.phpt +++ b/ext/sodium/tests/sodium_length_mismatch_error.phpt @@ -12,8 +12,8 @@ foreach (['sodium_add', 'sodium_memcmp', 'sodium_compare'] as $function) { try { $first = $short; $function($first, $long); - } catch (SodiumException $e) { - echo $e->getMessage(), "\n"; + } catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } } @@ -24,8 +24,8 @@ foreach ((new ReflectionFunction('sodium_add'))->getParameters() as $parameter) ?> --EXPECT-- -sodium_add(): Argument #1 ($string1) and argument #2 ($string2) must have the same length -sodium_memcmp(): Argument #1 ($string1) and argument #2 ($string2) must have the same length -sodium_compare(): Argument #1 ($string1) and argument #2 ($string2) must have the same length +SodiumException: sodium_add(): Argument #1 ($string1) and argument #2 ($string2) must have the same length +SodiumException: sodium_memcmp(): Argument #1 ($string1) and argument #2 ($string2) must have the same length +SodiumException: sodium_compare(): Argument #1 ($string1) and argument #2 ($string2) must have the same length $string1 $string2