Skip to content
Open
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
6 changes: 3 additions & 3 deletions ext/sodium/libsodium.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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));
Expand Down Expand Up @@ -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,
Expand Down
31 changes: 31 additions & 0 deletions ext/sodium/tests/sodium_length_mismatch_error.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
--TEST--
The length-mismatch errors name the real second parameter
--EXTENSIONS--
sodium
--FILE--
<?php

$short = str_repeat("\x01", 4);
$long = str_repeat("\x01", 8);

foreach (['sodium_add', 'sodium_memcmp', 'sodium_compare'] as $function) {
try {
$first = $short;
$function($first, $long);
} catch (Throwable $e) {
echo $e::class, ': ', $e->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
Loading