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..098f309f5dab --- /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-- +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