@@ -550,7 +550,7 @@ PHPAPI timelib_tzinfo *get_timezone_info(void)
550
550
tz = guess_timezone (DATE_TIMEZONEDB );
551
551
tzi = php_date_parse_tzfile (tz , DATE_TIMEZONEDB );
552
552
if (! tzi ) {
553
- php_error_docref (NULL , E_ERROR , "Timezone database is corrupt - this should * never* happen! " );
553
+ zend_throw_error (NULL , "Timezone database is corrupt. Please file a bug report as this should never happen" );
554
554
}
555
555
return tzi ;
556
556
}
@@ -961,7 +961,7 @@ PHP_FUNCTION(idate)
961
961
962
962
ret = php_idate (ZSTR_VAL (format )[0 ], ts , 0 );
963
963
if (ret == -1 ) {
964
- php_error_docref (NULL , E_WARNING , "Unrecognized date format token. " );
964
+ php_error_docref (NULL , E_WARNING , "Unrecognized date format token" );
965
965
RETURN_FALSE ;
966
966
}
967
967
RETURN_LONG (ret );
@@ -1009,7 +1009,7 @@ PHPAPI zend_long php_parse_date(const char *string, zend_long *now)
1009
1009
PHP_FUNCTION (strtotime )
1010
1010
{
1011
1011
zend_string * times ;
1012
- int error1 , error2 ;
1012
+ int parse_error , epoch_does_not_fit_in_zend_long ;
1013
1013
timelib_error_container * error ;
1014
1014
zend_long preset_ts , ts ;
1015
1015
zend_bool preset_ts_is_null = 1 ;
@@ -1022,6 +1022,11 @@ PHP_FUNCTION(strtotime)
1022
1022
Z_PARAM_LONG_OR_NULL (preset_ts , preset_ts_is_null )
1023
1023
ZEND_PARSE_PARAMETERS_END ();
1024
1024
1025
+ /* timelib_strtotime() expects the string to not be empty */
1026
+ if (ZSTR_LEN (times ) == 0 ) {
1027
+ RETURN_FALSE ;
1028
+ }
1029
+
1025
1030
tzi = get_timezone_info ();
1026
1031
1027
1032
now = timelib_time_ctor ();
@@ -1032,20 +1037,27 @@ PHP_FUNCTION(strtotime)
1032
1037
1033
1038
t = timelib_strtotime (ZSTR_VAL (times ), ZSTR_LEN (times ), & error ,
1034
1039
DATE_TIMEZONEDB , php_date_parse_tzfile_wrapper );
1035
- error1 = error -> error_count ;
1040
+ parse_error = error -> error_count ;
1036
1041
timelib_error_container_dtor (error );
1042
+ if (parse_error ) {
1043
+ timelib_time_dtor (now );
1044
+ timelib_time_dtor (t );
1045
+ RETURN_FALSE ;
1046
+ }
1047
+
1037
1048
timelib_fill_holes (t , now , TIMELIB_NO_CLONE );
1038
1049
timelib_update_ts (t , tzi );
1039
- ts = timelib_date_to_int (t , & error2 );
1050
+ ts = timelib_date_to_int (t , & epoch_does_not_fit_in_zend_long );
1040
1051
1041
1052
timelib_time_dtor (now );
1042
1053
timelib_time_dtor (t );
1043
1054
1044
- if (error1 || error2 ) {
1055
+ if (epoch_does_not_fit_in_zend_long ) {
1056
+ php_error_docref (NULL , E_WARNING , "Epoch doesn't fit in a PHP integer" );
1045
1057
RETURN_FALSE ;
1046
- } else {
1047
- RETURN_LONG (ts );
1048
1058
}
1059
+
1060
+ RETURN_LONG (ts );
1049
1061
}
1050
1062
/* }}} */
1051
1063
@@ -1057,7 +1069,7 @@ PHPAPI void php_mktime(INTERNAL_FUNCTION_PARAMETERS, int gmt)
1057
1069
timelib_time * now ;
1058
1070
timelib_tzinfo * tzi = NULL ;
1059
1071
zend_long ts , adjust_seconds = 0 ;
1060
- int error ;
1072
+ int epoch_does_not_fit_in_zend_long ;
1061
1073
1062
1074
ZEND_PARSE_PARAMETERS_START (1 , 6 )
1063
1075
Z_PARAM_LONG (hou )
@@ -1115,15 +1127,18 @@ PHPAPI void php_mktime(INTERNAL_FUNCTION_PARAMETERS, int gmt)
1115
1127
}
1116
1128
1117
1129
/* Clean up and return */
1118
- ts = timelib_date_to_int (now , & error );
1119
- ts += adjust_seconds ;
1120
- timelib_time_dtor (now );
1130
+ ts = timelib_date_to_int (now , & epoch_does_not_fit_in_zend_long );
1121
1131
1122
- if (error ) {
1132
+ if (epoch_does_not_fit_in_zend_long ) {
1133
+ timelib_time_dtor (now );
1134
+ php_error_docref (NULL , E_WARNING , "Epoch doesn't fit in a PHP integer" );
1123
1135
RETURN_FALSE ;
1124
- } else {
1125
- RETURN_LONG (ts );
1126
1136
}
1137
+
1138
+ ts += adjust_seconds ;
1139
+ timelib_time_dtor (now );
1140
+
1141
+ RETURN_LONG (ts );
1127
1142
}
1128
1143
/* }}} */
1129
1144
@@ -2781,7 +2796,7 @@ static int php_date_modify(zval *object, char *modify, size_t modify_len) /* {{{
2781
2796
dateobj = Z_PHPDATE_P (object );
2782
2797
2783
2798
if (!(dateobj -> time )) {
2784
- php_error_docref (NULL , E_WARNING , "The DateTime object has not been correctly initialized by its constructor" );
2799
+ zend_throw_error (NULL , "The DateTime object has not been correctly initialized by its constructor" );
2785
2800
return 0 ;
2786
2801
}
2787
2802
@@ -3309,7 +3324,7 @@ PHP_FUNCTION(date_timestamp_get)
3309
3324
zval * object ;
3310
3325
php_date_obj * dateobj ;
3311
3326
zend_long timestamp ;
3312
- int error ;
3327
+ int epoch_does_not_fit_in_zend_long ;
3313
3328
3314
3329
if (zend_parse_method_parameters (ZEND_NUM_ARGS (), getThis (), "O" , & object , date_ce_interface ) == FAILURE ) {
3315
3330
RETURN_THROWS ();
@@ -3318,12 +3333,14 @@ PHP_FUNCTION(date_timestamp_get)
3318
3333
DATE_CHECK_INITIALIZED (dateobj -> time , DateTime );
3319
3334
timelib_update_ts (dateobj -> time , NULL );
3320
3335
3321
- timestamp = timelib_date_to_int (dateobj -> time , & error );
3322
- if ( error ) {
3323
- RETURN_FALSE ;
3324
- } else {
3325
- RETVAL_LONG ( timestamp );
3336
+ timestamp = timelib_date_to_int (dateobj -> time , & epoch_does_not_fit_in_zend_long );
3337
+
3338
+ if ( epoch_does_not_fit_in_zend_long ) {
3339
+ zend_value_error ( "Epoch doesn't fit in a PHP integer" );
3340
+ RETURN_THROWS ( );
3326
3341
}
3342
+
3343
+ RETURN_LONG (timestamp );
3327
3344
}
3328
3345
/* }}} */
3329
3346
@@ -3387,7 +3404,7 @@ PHP_FUNCTION(timezone_open)
3387
3404
php_timezone_obj * tzobj ;
3388
3405
3389
3406
ZEND_PARSE_PARAMETERS_START (1 , 1 )
3390
- Z_PARAM_STR (tz )
3407
+ Z_PARAM_PATH_STR (tz ) /* To prevent null bytes */
3391
3408
ZEND_PARSE_PARAMETERS_END ();
3392
3409
3393
3410
tzobj = Z_PHPTIMEZONE_P (php_date_instantiate (date_ce_timezone , return_value ));
@@ -3406,7 +3423,7 @@ PHP_METHOD(DateTimeZone, __construct)
3406
3423
zend_error_handling error_handling ;
3407
3424
3408
3425
ZEND_PARSE_PARAMETERS_START (1 , 1 )
3409
- Z_PARAM_STR (tz )
3426
+ Z_PARAM_PATH_STR (tz ) /* To prevent null bytes */
3410
3427
ZEND_PARSE_PARAMETERS_END ();
3411
3428
3412
3429
zend_replace_error_handling (EH_THROW , NULL , & error_handling );
@@ -4336,8 +4353,9 @@ PHP_FUNCTION(timezone_identifiers_list)
4336
4353
4337
4354
/* Extra validation */
4338
4355
if (what == PHP_DATE_TIMEZONE_PER_COUNTRY && option_len != 2 ) {
4339
- php_error_docref (NULL , E_NOTICE , "A two-letter ISO 3166-1 compatible country code is expected" );
4340
- RETURN_FALSE ;
4356
+ zend_argument_value_error (2 , "must be a two-letter ISO 3166-1 compatible country code "
4357
+ "when argument #1 ($timezoneGroup) is DateTimeZone::PER_COUNTRY" );
4358
+ RETURN_THROWS ();
4341
4359
}
4342
4360
4343
4361
tzdb = DATE_TIMEZONEDB ;
0 commit comments