@@ -614,7 +614,12 @@ static const char *zend_ini_consume_quantity_prefix(const char *const digits, co
614614 return digits_consumed ;
615615}
616616
617- static zend_ulong zend_ini_parse_quantity_internal (const zend_string * value , zend_ini_parse_quantity_signed_result_t signed_result , zend_string * * errstr ) /* {{{ */
617+ static zend_ulong zend_ini_parse_quantity_internal (
618+ const zend_string * value ,
619+ zend_ini_parse_quantity_signed_result_t signed_result ,
620+ zend_string * * errstr ,
621+ bool strict
622+ ) /* {{{ */
618623{
619624 char * digits_end = NULL ;
620625 const char * str = ZSTR_VAL (value );
@@ -634,6 +639,18 @@ static zend_ulong zend_ini_parse_quantity_internal(const zend_string *value, zen
634639 while (digits < str_end && zend_is_whitespace (* (str_end - 1 ))) {-- str_end ;}
635640
636641 if (digits == str_end ) {
642+ if (strict ) {
643+ if (ZSTR_LEN (value ) == 0 ) {
644+ * errstr = zend_strpprintf (0 , "Invalid quantity \"\": no valid leading digits" );
645+ } else {
646+ smart_str_append_escaped (& invalid , ZSTR_VAL (value ), ZSTR_LEN (value ));
647+ smart_str_0 (& invalid );
648+ * errstr = zend_strpprintf (0 , "Invalid quantity \"%s\": no valid leading digits" ,
649+ ZSTR_VAL (invalid .s ));
650+ smart_str_free (& invalid );
651+ }
652+ return 0 ;
653+ }
637654 * errstr = NULL ;
638655 return 0 ;
639656 }
@@ -653,8 +670,13 @@ static zend_ulong zend_ini_parse_quantity_internal(const zend_string *value, zen
653670 smart_str_append_escaped (& invalid , ZSTR_VAL (value ), ZSTR_LEN (value ));
654671 smart_str_0 (& invalid );
655672
656- * errstr = zend_strpprintf (0 , "Invalid quantity \"%s\": no valid leading digits, interpreting as \"0\" for backwards compatibility" ,
657- ZSTR_VAL (invalid .s ));
673+ if (strict ) {
674+ * errstr = zend_strpprintf (0 , "Invalid quantity \"%s\": no valid leading digits" ,
675+ ZSTR_VAL (invalid .s ));
676+ } else {
677+ * errstr = zend_strpprintf (0 , "Invalid quantity \"%s\": no valid leading digits, interpreting as \"0\" for backwards compatibility" ,
678+ ZSTR_VAL (invalid .s ));
679+ }
658680
659681 smart_str_free (& invalid );
660682 return 0 ;
@@ -690,8 +712,12 @@ static zend_ulong zend_ini_parse_quantity_internal(const zend_string *value, zen
690712 base = 2 ;
691713 break ;
692714 default :
693- * errstr = zend_strpprintf (0 , "Invalid prefix \"0%c\", interpreting as \"0\" for backwards compatibility" ,
694- digits [1 ]);
715+ if (strict ) {
716+ * errstr = zend_strpprintf (0 , "Invalid prefix \"0%c\"" , digits [1 ]);
717+ } else {
718+ * errstr = zend_strpprintf (0 , "Invalid prefix \"0%c\", interpreting as \"0\" for backwards compatibility" ,
719+ digits [1 ]);
720+ }
695721 return 0 ;
696722 }
697723 digits += 2 ;
@@ -702,8 +728,13 @@ static zend_ulong zend_ini_parse_quantity_internal(const zend_string *value, zen
702728 smart_str_append_escaped (& invalid , ZSTR_VAL (value ), ZSTR_LEN (value ));
703729 smart_str_0 (& invalid );
704730
705- * errstr = zend_strpprintf (0 , "Invalid quantity \"%s\": no digits after base prefix, interpreting as \"0\" for backwards compatibility" ,
706- ZSTR_VAL (invalid .s ));
731+ if (strict ) {
732+ * errstr = zend_strpprintf (0 , "Invalid quantity \"%s\": no digits after base prefix" ,
733+ ZSTR_VAL (invalid .s ));
734+ } else {
735+ * errstr = zend_strpprintf (0 , "Invalid quantity \"%s\": no digits after base prefix, interpreting as \"0\" for backwards compatibility" ,
736+ ZSTR_VAL (invalid .s ));
737+ }
707738
708739 smart_str_free (& invalid );
709740 return 0 ;
@@ -744,8 +775,13 @@ static zend_ulong zend_ini_parse_quantity_internal(const zend_string *value, zen
744775 smart_str_append_escaped (& invalid , ZSTR_VAL (value ), ZSTR_LEN (value ));
745776 smart_str_0 (& invalid );
746777
747- * errstr = zend_strpprintf (0 , "Invalid quantity \"%s\": no valid leading digits, interpreting as \"0\" for backwards compatibility" ,
748- ZSTR_VAL (invalid .s ));
778+ if (strict ) {
779+ * errstr = zend_strpprintf (0 , "Invalid quantity \"%s\": no valid leading digits" ,
780+ ZSTR_VAL (invalid .s ));
781+ } else {
782+ * errstr = zend_strpprintf (0 , "Invalid quantity \"%s\": no valid leading digits, interpreting as \"0\" for backwards compatibility" ,
783+ ZSTR_VAL (invalid .s ));
784+ }
749785
750786 smart_str_free (& invalid );
751787 return 0 ;
@@ -781,8 +817,13 @@ static zend_ulong zend_ini_parse_quantity_internal(const zend_string *value, zen
781817 smart_str_append_escaped (& chr , str_end - 1 , 1 );
782818 smart_str_0 (& chr );
783819
784- * errstr = zend_strpprintf (0 , "Invalid quantity \"%s\": unknown multiplier \"%s\", interpreting as \"%s\" for backwards compatibility" ,
785- ZSTR_VAL (invalid .s ), ZSTR_VAL (chr .s ), ZSTR_VAL (interpreted .s ));
820+ if (strict ) {
821+ * errstr = zend_strpprintf (0 , "Invalid quantity \"%s\": unknown multiplier \"%s\"" ,
822+ ZSTR_VAL (invalid .s ), ZSTR_VAL (chr .s ));
823+ } else {
824+ * errstr = zend_strpprintf (0 , "Invalid quantity \"%s\": unknown multiplier \"%s\", interpreting as \"%s\" for backwards compatibility" ,
825+ ZSTR_VAL (invalid .s ), ZSTR_VAL (chr .s ), ZSTR_VAL (interpreted .s ));
826+ }
786827
787828 smart_str_free (& invalid );
788829 smart_str_free (& interpreted );
@@ -815,8 +856,13 @@ static zend_ulong zend_ini_parse_quantity_internal(const zend_string *value, zen
815856 smart_str_append_escaped (& chr , str_end - 1 , 1 );
816857 smart_str_0 (& chr );
817858
818- * errstr = zend_strpprintf (0 , "Invalid quantity \"%s\", interpreting as \"%s%s\" for backwards compatibility" ,
819- ZSTR_VAL (invalid .s ), ZSTR_VAL (interpreted .s ), ZSTR_VAL (chr .s ));
859+ if (strict ) {
860+ * errstr = zend_strpprintf (0 , "Invalid quantity \"%s\": invalid characters before multiplier \"%s\"" ,
861+ ZSTR_VAL (invalid .s ), ZSTR_VAL (chr .s ));
862+ } else {
863+ * errstr = zend_strpprintf (0 , "Invalid quantity \"%s\", interpreting as \"%s%s\" for backwards compatibility" ,
864+ ZSTR_VAL (invalid .s ), ZSTR_VAL (interpreted .s ), ZSTR_VAL (chr .s ));
865+ }
820866
821867 smart_str_free (& invalid );
822868 smart_str_free (& interpreted );
@@ -833,8 +879,13 @@ static zend_ulong zend_ini_parse_quantity_internal(const zend_string *value, zen
833879 /* Not specifying the resulting value here because the caller may make
834880 * additional conversions. Not specifying the allowed range
835881 * because the caller may do narrower range checks. */
836- * errstr = zend_strpprintf (0 , "Invalid quantity \"%s\": value is out of range, using overflow result for backwards compatibility" ,
837- ZSTR_VAL (invalid .s ));
882+ if (strict ) {
883+ * errstr = zend_strpprintf (0 , "Invalid quantity \"%s\": value is out of range" ,
884+ ZSTR_VAL (invalid .s ));
885+ } else {
886+ * errstr = zend_strpprintf (0 , "Invalid quantity \"%s\": value is out of range, using overflow result for backwards compatibility" ,
887+ ZSTR_VAL (invalid .s ));
888+ }
838889
839890 smart_str_free (& invalid );
840891 smart_str_free (& interpreted );
@@ -850,13 +901,25 @@ static zend_ulong zend_ini_parse_quantity_internal(const zend_string *value, zen
850901
851902ZEND_API zend_long zend_ini_parse_quantity (const zend_string * value , zend_string * * errstr ) /* {{{ */
852903{
853- return (zend_long ) zend_ini_parse_quantity_internal (value , ZEND_INI_PARSE_QUANTITY_SIGNED , errstr );
904+ return (zend_long ) zend_ini_parse_quantity_internal (value , ZEND_INI_PARSE_QUANTITY_SIGNED , errstr , false );
854905}
855906/* }}} */
856907
857908ZEND_API zend_ulong zend_ini_parse_uquantity (const zend_string * value , zend_string * * errstr ) /* {{{ */
858909{
859- return zend_ini_parse_quantity_internal (value , ZEND_INI_PARSE_QUANTITY_UNSIGNED , errstr );
910+ return zend_ini_parse_quantity_internal (value , ZEND_INI_PARSE_QUANTITY_UNSIGNED , errstr , false);
911+ }
912+ /* }}} */
913+
914+ ZEND_API zend_result zend_ini_parse_quantity_strict (const zend_string * value , zend_long * result , zend_string * * errstr ) /* {{{ */
915+ {
916+ zend_long retval = (zend_long ) zend_ini_parse_quantity_internal (value , ZEND_INI_PARSE_QUANTITY_SIGNED , errstr , true);
917+ if (* errstr ) {
918+ return FAILURE ;
919+ }
920+
921+ * result = retval ;
922+ return SUCCESS ;
860923}
861924/* }}} */
862925
@@ -974,6 +1037,23 @@ ZEND_API ZEND_INI_MH(OnUpdateLong) /* {{{ */
9741037}
9751038/* }}} */
9761039
1040+ ZEND_API ZEND_INI_MH (OnUpdateLongStrict ) /* {{{ */
1041+ {
1042+ zend_long tmp ;
1043+ zend_string * errstr ;
1044+ if (UNEXPECTED (zend_ini_parse_quantity_strict (new_value , & tmp , & errstr ) == FAILURE )) {
1045+ zend_error (E_WARNING , "Invalid \"%s\" setting. %s" , ZSTR_VAL (entry -> name ), ZSTR_VAL (errstr ));
1046+ zend_string_release (errstr );
1047+ return FAILURE ;
1048+ }
1049+
1050+ zend_long * p = ZEND_INI_GET_ADDR ();
1051+ * p = tmp ;
1052+
1053+ return SUCCESS ;
1054+ }
1055+ /* }}} */
1056+
9771057ZEND_API ZEND_INI_MH (OnUpdateLongGEZero ) /* {{{ */
9781058{
9791059 zend_long tmp = zend_ini_parse_quantity_warn (new_value , entry -> name );
0 commit comments