Commit 0e8d4623916 for php.net

commit 0e8d46239162e3f6822acb8e57b5ec74ab28192a
Author: Louis-Arnaud <la.catoire@gmail.com>
Date:   Sun Aug 23 16:07:28 2026 +0200

    ext/sodium: Fix parameter name in the length-mismatch errors (#23396)

    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.

    Co-authored-by: NickSdot <32384907+NickSdot@users.noreply.github.com>

diff --git a/ext/sodium/libsodium.c b/ext/sodium/libsodium.c
index 8c85991150b..7b8f41f2f4b 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 00000000000..098f309f5da
--- /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--
+<?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