@@ -547,6 +547,34 @@ typedef enum {
547
547
ZEND_INI_PARSE_QUANTITY_UNSIGNED ,
548
548
} zend_ini_parse_quantity_signed_result_t ;
549
549
550
+ static const char * zend_ini_consume_quantity_prefix (const char * const digits , const char * const str_end ) {
551
+ const char * digits_consumed = digits ;
552
+ /* Ignore leading whitespace. */
553
+ while (digits_consumed < str_end && zend_is_whitespace (* digits_consumed )) {++ digits_consumed ;}
554
+ if (digits_consumed [0 ] == '+' || digits_consumed [0 ] == '-' ) {
555
+ ++ digits_consumed ;
556
+ }
557
+
558
+ if (digits_consumed [0 ] == '0' && !isdigit (digits_consumed [1 ])) {
559
+ /* Value is just 0 */
560
+ if ((digits_consumed + 1 ) == str_end ) {
561
+ return digits ;
562
+ }
563
+
564
+ switch (digits_consumed [1 ]) {
565
+ case 'x' :
566
+ case 'X' :
567
+ case 'o' :
568
+ case 'O' :
569
+ case 'b' :
570
+ case 'B' :
571
+ digits_consumed += 2 ;
572
+ break ;
573
+ }
574
+ }
575
+ return digits_consumed ;
576
+ }
577
+
550
578
static zend_ulong zend_ini_parse_quantity_internal (zend_string * value , zend_ini_parse_quantity_signed_result_t signed_result , zend_string * * errstr ) /* {{{ */
551
579
{
552
580
char * digits_end = NULL ;
@@ -634,6 +662,18 @@ static zend_ulong zend_ini_parse_quantity_internal(zend_string *value, zend_ini_
634
662
smart_str_append_escaped (& invalid , ZSTR_VAL (value ), ZSTR_LEN (value ));
635
663
smart_str_0 (& invalid );
636
664
665
+ * errstr = zend_strpprintf (0 , "Invalid quantity \"%s\": no digits after base prefix, interpreting as \"0\" for backwards compatibility" ,
666
+ ZSTR_VAL (invalid .s ));
667
+
668
+ smart_str_free (& invalid );
669
+ return 0 ;
670
+ }
671
+ if (UNEXPECTED (digits != zend_ini_consume_quantity_prefix (digits , str_end ))) {
672
+ /* Escape the string to avoid null bytes and to make non-printable chars
673
+ * visible */
674
+ smart_str_append_escaped (& invalid , ZSTR_VAL (value ), ZSTR_LEN (value ));
675
+ smart_str_0 (& invalid );
676
+
637
677
* errstr = zend_strpprintf (0 , "Invalid quantity \"%s\": no digits after base prefix, interpreting as \"0\" for backwards compatibility" ,
638
678
ZSTR_VAL (invalid .s ));
639
679
0 commit comments