@@ -351,9 +351,10 @@ static const mbfl_encoding *php_mb_get_encoding(zend_string *encoding_name, uint
351
351
352
352
/* {{{ static int php_mb_parse_encoding_list()
353
353
* Return FAILURE if input contains any illegal encoding, otherwise SUCCESS.
354
+ * Emits a ValueError in function context and a warning in INI context, in INI context arg_num must be 0.
354
355
*/
355
- static int
356
- php_mb_parse_encoding_list ( const char * value , size_t value_length , const mbfl_encoding * * * return_list , size_t * return_size , int persistent )
356
+ static int php_mb_parse_encoding_list ( const char * value , size_t value_length ,
357
+ const mbfl_encoding * * * return_list , size_t * return_size , int persistent , uint32_t arg_num )
357
358
{
358
359
if (value == NULL || value_length == 0 ) {
359
360
* return_list = NULL ;
@@ -416,15 +417,20 @@ php_mb_parse_encoding_list(const char *value, size_t value_length, const mbfl_en
416
417
}
417
418
} else {
418
419
const mbfl_encoding * encoding = mbfl_name2encoding (p1 );
419
- if (encoding ) {
420
- * entry ++ = encoding ;
421
- n ++ ;
422
- } else {
423
- php_error_docref (NULL , E_WARNING , "Unknown encoding \"%s\"" , p1 );
420
+ if (!encoding ) {
421
+ /* Called from an INI setting modification */
422
+ if (arg_num == 0 ) {
423
+ php_error_docref ("ref.mbstring" , E_WARNING , "INI setting contains invalid encoding \"%s\"" , p1 );
424
+ } else {
425
+ zend_argument_value_error (arg_num , "contains invalid encoding \"%s\"" , p1 );
426
+ }
424
427
efree (tmpstr );
425
428
pefree (list , persistent );
426
429
return FAILURE ;
427
430
}
431
+
432
+ * entry ++ = encoding ;
433
+ n ++ ;
428
434
}
429
435
p1 = p2 + 1 ;
430
436
} while (n < size && p2 != NULL );
@@ -439,9 +445,10 @@ php_mb_parse_encoding_list(const char *value, size_t value_length, const mbfl_en
439
445
440
446
/* {{{ static int php_mb_parse_encoding_array()
441
447
* Return FAILURE if input contains any illegal encoding, otherwise SUCCESS.
448
+ * Emits a ValueError in function context and a warning in INI context, in INI context arg_num must be 0.
442
449
*/
443
- static int
444
- php_mb_parse_encoding_array ( HashTable * target_hash , const mbfl_encoding * * * return_list , size_t * return_size )
450
+ static int php_mb_parse_encoding_array ( HashTable * target_hash , const mbfl_encoding * * * return_list ,
451
+ size_t * return_size , uint32_t arg_num )
445
452
{
446
453
/* Allocate enough space to include the default detect order if "auto" is used. */
447
454
size_t size = zend_hash_num_elements (target_hash ) + MBSTRG (default_detect_order_list_size );
@@ -475,8 +482,7 @@ php_mb_parse_encoding_array(HashTable *target_hash, const mbfl_encoding ***retur
475
482
* entry ++ = encoding ;
476
483
n ++ ;
477
484
} else {
478
- php_error_docref (NULL , E_WARNING ,
479
- "Unknown encoding \"%s\"" , ZSTR_VAL (encoding_str ));
485
+ zend_argument_value_error (arg_num , "contains invalid encoding \"%s\"" , ZSTR_VAL (encoding_str ));
480
486
zend_string_release (encoding_str );
481
487
efree (list );
482
488
return FAILURE ;
@@ -576,7 +582,7 @@ static size_t php_mb_zend_encoding_converter(unsigned char **to, size_t *to_leng
576
582
577
583
static int php_mb_zend_encoding_list_parser (const char * encoding_list , size_t encoding_list_len , const zend_encoding * * * return_list , size_t * return_size , int persistent )
578
584
{
579
- return php_mb_parse_encoding_list (encoding_list , encoding_list_len , (const mbfl_encoding * * * )return_list , return_size , persistent );
585
+ return php_mb_parse_encoding_list (encoding_list , encoding_list_len , (const mbfl_encoding * * * )return_list , return_size , persistent , 0 );
580
586
}
581
587
582
588
static const zend_encoding * php_mb_zend_internal_encoding_getter (void )
@@ -869,7 +875,7 @@ static PHP_INI_MH(OnUpdate_mbstring_detect_order)
869
875
return SUCCESS ;
870
876
}
871
877
872
- if (FAILURE == php_mb_parse_encoding_list (ZSTR_VAL (new_value ), ZSTR_LEN (new_value ), & list , & size , 1 ) || size == 0 ) {
878
+ if (FAILURE == php_mb_parse_encoding_list (ZSTR_VAL (new_value ), ZSTR_LEN (new_value ), & list , & size , 1 , 0 ) || size == 0 ) {
873
879
return FAILURE ;
874
880
}
875
881
@@ -885,7 +891,7 @@ static PHP_INI_MH(OnUpdate_mbstring_detect_order)
885
891
static int _php_mb_ini_mbstring_http_input_set (const char * new_value , size_t new_value_length ) {
886
892
const mbfl_encoding * * list ;
887
893
size_t size ;
888
- if (FAILURE == php_mb_parse_encoding_list (new_value , new_value_length , & list , & size , 1 ) || size == 0 ) {
894
+ if (FAILURE == php_mb_parse_encoding_list (new_value , new_value_length , & list , & size , 1 , 0 ) || size == 0 ) {
889
895
return FAILURE ;
890
896
}
891
897
if (MBSTRG (http_input_list )) {
@@ -1551,12 +1557,12 @@ PHP_FUNCTION(mb_detect_order)
1551
1557
const mbfl_encoding * * list ;
1552
1558
size_t size ;
1553
1559
if (order_ht ) {
1554
- if (FAILURE == php_mb_parse_encoding_array (order_ht , & list , & size )) {
1555
- RETURN_FALSE ;
1560
+ if (FAILURE == php_mb_parse_encoding_array (order_ht , & list , & size , 1 )) {
1561
+ RETURN_THROWS () ;
1556
1562
}
1557
1563
} else {
1558
- if (FAILURE == php_mb_parse_encoding_list (ZSTR_VAL (order_str ), ZSTR_LEN (order_str ), & list , & size , 0 )) {
1559
- RETURN_FALSE ;
1564
+ if (FAILURE == php_mb_parse_encoding_list (ZSTR_VAL (order_str ), ZSTR_LEN (order_str ), & list , & size , 0 , 1 )) {
1565
+ RETURN_THROWS () ;
1560
1566
}
1561
1567
}
1562
1568
@@ -2699,13 +2705,14 @@ PHP_FUNCTION(mb_convert_encoding)
2699
2705
}
2700
2706
2701
2707
if (from_encodings_ht ) {
2702
- if (php_mb_parse_encoding_array (from_encodings_ht , & from_encodings , & num_from_encodings ) == FAILURE ) {
2703
- RETURN_FALSE ;
2708
+ if (php_mb_parse_encoding_array (from_encodings_ht , & from_encodings , & num_from_encodings , 3 ) == FAILURE ) {
2709
+ RETURN_THROWS () ;
2704
2710
}
2705
2711
free_from_encodings = 1 ;
2706
2712
} else if (from_encodings_str ) {
2707
- if (php_mb_parse_encoding_list (ZSTR_VAL (from_encodings_str ), ZSTR_LEN (from_encodings_str ), & from_encodings , & num_from_encodings , 0 ) == FAILURE ) {
2708
- RETURN_FALSE ;
2713
+ if (php_mb_parse_encoding_list (ZSTR_VAL (from_encodings_str ), ZSTR_LEN (from_encodings_str ),
2714
+ & from_encodings , & num_from_encodings , 0 , 3 ) == FAILURE ) {
2715
+ RETURN_THROWS ();
2709
2716
}
2710
2717
free_from_encodings = 1 ;
2711
2718
} else {
@@ -2885,13 +2892,13 @@ PHP_FUNCTION(mb_detect_encoding)
2885
2892
2886
2893
/* make encoding list */
2887
2894
if (encoding_ht ) {
2888
- if (FAILURE == php_mb_parse_encoding_array (encoding_ht , & elist , & size )) {
2889
- RETURN_FALSE ;
2895
+ if (FAILURE == php_mb_parse_encoding_array (encoding_ht , & elist , & size , 2 )) {
2896
+ RETURN_THROWS () ;
2890
2897
}
2891
2898
free_elist = 1 ;
2892
2899
} else if (encoding_str ) {
2893
- if (FAILURE == php_mb_parse_encoding_list (ZSTR_VAL (encoding_str ), ZSTR_LEN (encoding_str ), & elist , & size , 0 )) {
2894
- RETURN_FALSE ;
2900
+ if (FAILURE == php_mb_parse_encoding_list (ZSTR_VAL (encoding_str ), ZSTR_LEN (encoding_str ), & elist , & size , 0 , 2 )) {
2901
+ RETURN_THROWS () ;
2895
2902
}
2896
2903
free_elist = 1 ;
2897
2904
} else {
@@ -3285,12 +3292,12 @@ PHP_FUNCTION(mb_convert_variables)
3285
3292
3286
3293
/* pre-conversion encoding */
3287
3294
if (from_enc_ht ) {
3288
- if (php_mb_parse_encoding_array (from_enc_ht , & elist , & elistsz ) == FAILURE ) {
3289
- RETURN_FALSE ;
3295
+ if (php_mb_parse_encoding_array (from_enc_ht , & elist , & elistsz , 2 ) == FAILURE ) {
3296
+ RETURN_THROWS () ;
3290
3297
}
3291
3298
} else {
3292
- if (php_mb_parse_encoding_list (ZSTR_VAL (from_enc_str ), ZSTR_LEN (from_enc_str ), & elist , & elistsz , 0 ) == FAILURE ) {
3293
- RETURN_FALSE ;
3299
+ if (php_mb_parse_encoding_list (ZSTR_VAL (from_enc_str ), ZSTR_LEN (from_enc_str ), & elist , & elistsz , 0 , 2 ) == FAILURE ) {
3300
+ RETURN_THROWS () ;
3294
3301
}
3295
3302
}
3296
3303
0 commit comments