From 118aacee28140e7a1ed911e474fd8a599c32e84f Mon Sep 17 00:00:00 2001 From: Clemens Schwaighofer Date: Wed, 14 Jan 2026 15:07:38 +0900 Subject: [PATCH] Bug in RamdomKey::validateRandomKeyData when passing large character sets The check for stringlength was done on the set key range in the class var and not the variable passed on in the method. So if we cold call randomKey with a key character list and not the default list it failed with invalid max length --- www/admin/class_test.randomkey.php | 15 +++++++++++++++ www/admin/class_test.strings.php | 10 ++++++++++ www/lib/CoreLibs/Create/RandomKey.php | 2 +- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/www/admin/class_test.randomkey.php b/www/admin/class_test.randomkey.php index c0c531a3..c6a77c6b 100644 --- a/www/admin/class_test.randomkey.php +++ b/www/admin/class_test.randomkey.php @@ -34,6 +34,20 @@ print ""; print '
Class Test Master
'; print '

' . $PAGE_NAME . '

'; +$output = RandomKey::randomKeyGen( + 12, + [ + 0 => 'A', 1 => 'B', 2 => 'C', 3 => 'D', 4 => 'E', 5 => 'F', 6 => 'G', 7 => 'H', 8 => 'I', 9 => 'J', 10 => 'K', + 11 => 'L', 12 => 'M', 13 => 'N', 14 => 'O', 15 => 'P', 16 => 'Q', 17 => 'R', 18 => 'S', 19 => 'T', 20 => 'U', + 21 => 'V', 22 => 'W', 23 => 'X', 24 => 'Y', 25 => 'Z', 26 => 'a', 27 => 'b', 28 => 'c', 29 => 'd', 30 => 'e', + 31 => 'f', 32 => 'g', 33 => 'h', 34 => 'i', 35 => 'j', 36 => 'k', 37 => 'l', 38 => 'm', 39 => 'n', 40 => 'o', + 41 => 'p', 42 => 'q', 43 => 'r', 44 => 's', 45 => 't', 46 => 'u', 47 => 'v', 48 => 'w', 49 => 'x', 50 => 'y', + 51 => 'z', 52 => '0', 53 => '1', 54 => '2', 55 => '3', 56 => '4', 57 => '5', 58 => '6', 59 => '7', 60 => '8', + 61 => '9' + ] +); +print "CUSTOM OUTPUT: " . $output . "
"; + $key_length = 10; $key_length_b = 5; $key_lenght_long = 64; @@ -54,6 +68,7 @@ print "===
"; $_array = new CoreLibs\Create\RandomKey(['A', 'F', 'B'], ['1', '5', '9']); print "C->RANDOMKEYGEN(pre set): " . $_array->randomKeyGen() . "
"; + print ""; // __END__ diff --git a/www/admin/class_test.strings.php b/www/admin/class_test.strings.php index fe2d0c75..00234f3b 100644 --- a/www/admin/class_test.strings.php +++ b/www/admin/class_test.strings.php @@ -122,6 +122,16 @@ print "Combined strings A: " . Strings::buildCharStringFromLists(['A', 'B', 'C'], ['0', '1', '2']) . "
"; print "Combined strings B: " . Strings::buildCharStringFromLists([['F'], ['G'], 'H'], [['5', ['6']], ['0'], '1', '2']) . "
"; +print "Combined strings C: " + . Strings::buildCharStringFromLists([ + 0 => 'A', 1 => 'B', 2 => 'C', 3 => 'D', 4 => 'E', 5 => 'F', 6 => 'G', 7 => 'H', 8 => 'I', 9 => 'J', 10 => 'K', + 11 => 'L', 12 => 'M', 13 => 'N', 14 => 'O', 15 => 'P', 16 => 'Q', 17 => 'R', 18 => 'S', 19 => 'T', 20 => 'U', + 21 => 'V', 22 => 'W', 23 => 'X', 24 => 'Y', 25 => 'Z', 26 => 'a', 27 => 'b', 28 => 'c', 29 => 'd', 30 => 'e', + 31 => 'f', 32 => 'g', 33 => 'h', 34 => 'i', 35 => 'j', 36 => 'k', 37 => 'l', 38 => 'm', 39 => 'n', 40 => 'o', + 41 => 'p', 42 => 'q', 43 => 'r', 44 => 's', 45 => 't', 46 => 'u', 47 => 'v', 48 => 'w', 49 => 'x', 50 => 'y', + 51 => 'z', 52 => '0', 53 => '1', 54 => '2', 55 => '3', 56 => '4', 57 => '5', 58 => '6', 59 => '7', 60 => '8', + 61 => '9' + ]) . "
"; $input_string = "AaBbCc"; print "Unique: " . Strings::removeDuplicates($input_string) . "
"; diff --git a/www/lib/CoreLibs/Create/RandomKey.php b/www/lib/CoreLibs/Create/RandomKey.php index 75593367..59b100e7 100644 --- a/www/lib/CoreLibs/Create/RandomKey.php +++ b/www/lib/CoreLibs/Create/RandomKey.php @@ -49,7 +49,7 @@ class RandomKey private static function validateRandomKeyData(array ...$key_range): string { $key_character_range = Strings::buildCharStringFromLists(...$key_range); - if (strlen(self::$key_character_range) <= 1) { + if (strlen($key_character_range) <= 1) { return ''; } return $key_character_range;