|
4 | 4 |
|
5 | 5 | namespace PhpMyAdmin;
|
6 | 6 |
|
| 7 | +use function array_filter; |
7 | 8 | use function array_intersect;
|
8 | 9 | use function array_map;
|
9 | 10 | use function explode;
|
|
14 | 15 | use function function_exists;
|
15 | 16 | use function fwrite;
|
16 | 17 | use function iconv;
|
| 18 | +use function is_string; |
17 | 19 | use function mb_convert_encoding;
|
18 | 20 | use function mb_convert_kana;
|
19 | 21 | use function mb_detect_encoding;
|
20 | 22 | use function mb_list_encodings;
|
| 23 | +use function preg_replace; |
| 24 | +use function str_contains; |
| 25 | +use function str_starts_with; |
21 | 26 | use function strtolower;
|
| 27 | +use function strtoupper; |
22 | 28 | use function tempnam;
|
23 | 29 | use function unlink;
|
24 | 30 |
|
@@ -156,11 +162,18 @@ public static function convertString(
|
156 | 162 | self::initEngine();
|
157 | 163 | }
|
158 | 164 |
|
| 165 | + $config = Config::getInstance(); |
| 166 | + $iconvExtraParams = ''; |
| 167 | + if ( |
| 168 | + isset($config->settings['IconvExtraParams']) |
| 169 | + && is_string($config->settings['IconvExtraParams']) |
| 170 | + && str_starts_with($config->settings['IconvExtraParams'], '//') |
| 171 | + ) { |
| 172 | + $iconvExtraParams = $config->settings['IconvExtraParams']; |
| 173 | + } |
| 174 | + |
159 | 175 | return match (self::$engine) {
|
160 |
| - self::ENGINE_ICONV => iconv( |
161 |
| - $srcCharset, |
162 |
| - $destCharset . (Config::getInstance()->settings['IconvExtraParams'] ?? ''), $what, |
163 |
| - ), |
| 176 | + self::ENGINE_ICONV => iconv($srcCharset, $destCharset . $iconvExtraParams, $what), |
164 | 177 | self::ENGINE_MB => mb_convert_encoding($what, $destCharset, $srcCharset),
|
165 | 178 | default => $what,
|
166 | 179 | };
|
@@ -310,7 +323,14 @@ public static function listEncodings(): array
|
310 | 323 | /* Most engines do not support listing */
|
311 | 324 | $config = Config::getInstance();
|
312 | 325 | if (self::$engine != self::ENGINE_MB) {
|
313 |
| - return $config->settings['AvailableCharsets']; |
| 326 | + return array_filter($config->settings['AvailableCharsets'], static function (string $charset): bool { |
| 327 | + // Removes any ignored character |
| 328 | + $normalizedCharset = strtoupper((string) preg_replace(['/[^A-Za-z0-9\-\/]/'], '', $charset)); |
| 329 | + |
| 330 | + // The character set ISO-2022-CN-EXT can be vulnerable (CVE-2024-2961). |
| 331 | + return ! str_contains($normalizedCharset, 'ISO-2022-CN-EXT') |
| 332 | + && ! str_contains($normalizedCharset, 'ISO2022CNEXT'); |
| 333 | + }); |
314 | 334 | }
|
315 | 335 |
|
316 | 336 | return array_intersect(
|
|
0 commit comments