@@ -553,7 +553,7 @@ PHPAPI timelib_tzinfo *get_timezone_info(void)
553
553
tz = guess_timezone (DATE_TIMEZONEDB );
554
554
tzi = php_date_parse_tzfile (tz , DATE_TIMEZONEDB );
555
555
if (! tzi ) {
556
- php_error_docref (NULL , E_ERROR , "Timezone database is corrupt - this should * never* happen! " );
556
+ zend_throw_error (NULL , "Timezone database is corrupt. Please file a bug report as this should never happen" );
557
557
}
558
558
return tzi ;
559
559
}
@@ -952,8 +952,8 @@ PHP_FUNCTION(idate)
952
952
ZEND_PARSE_PARAMETERS_END ();
953
953
954
954
if (ZSTR_LEN (format ) != 1 ) {
955
- php_error_docref ( NULL , E_WARNING , "idate format is one char " );
956
- RETURN_FALSE ;
955
+ zend_argument_value_error ( 1 , "must be one character " );
956
+ RETURN_THROWS () ;
957
957
}
958
958
959
959
if (ts_is_null ) {
@@ -962,8 +962,8 @@ PHP_FUNCTION(idate)
962
962
963
963
ret = php_idate (ZSTR_VAL (format )[0 ], ts , 0 );
964
964
if (ret == -1 ) {
965
- php_error_docref ( NULL , E_WARNING , "Unrecognized date format token. " );
966
- RETURN_FALSE ;
965
+ zend_argument_value_error ( 1 , "must be a valid date format token" );
966
+ RETURN_THROWS () ;
967
967
}
968
968
RETURN_LONG (ret );
969
969
}
@@ -1024,6 +1024,12 @@ PHP_FUNCTION(strtotime)
1024
1024
Z_PARAM_LONG_OR_NULL (preset_ts , preset_ts_is_null )
1025
1025
ZEND_PARSE_PARAMETERS_END ();
1026
1026
1027
+ /* timelib_strtotime() expects the string to not be empty */
1028
+ if (ZSTR_LEN (times ) == 0 ) {
1029
+ zend_argument_value_error (1 , "must not be empty" );
1030
+ RETURN_THROWS ();
1031
+ }
1032
+
1027
1033
tzi = get_timezone_info ();
1028
1034
1029
1035
now = timelib_time_ctor ();
@@ -1036,18 +1042,22 @@ PHP_FUNCTION(strtotime)
1036
1042
DATE_TIMEZONEDB , php_date_parse_tzfile_wrapper );
1037
1043
error1 = error -> error_count ;
1038
1044
timelib_error_container_dtor (error );
1045
+ if (error1 ) {
1046
+ timelib_time_dtor (now );
1047
+ timelib_time_dtor (t );
1048
+ RETURN_FALSE ;
1049
+ }
1050
+
1039
1051
timelib_fill_holes (t , now , TIMELIB_NO_CLONE );
1040
1052
timelib_update_ts (t , tzi );
1041
1053
ts = timelib_date_to_int (t , & error2 );
1054
+ /* Seconds since epoch must fit in a zend_long */
1055
+ ZEND_ASSERT (!error2 );
1042
1056
1043
1057
timelib_time_dtor (now );
1044
1058
timelib_time_dtor (t );
1045
1059
1046
- if (error1 || error2 ) {
1047
- RETURN_FALSE ;
1048
- } else {
1049
- RETURN_LONG (ts );
1050
- }
1060
+ RETURN_LONG (ts );
1051
1061
}
1052
1062
/* }}} */
1053
1063
@@ -1118,14 +1128,12 @@ PHPAPI void php_mktime(INTERNAL_FUNCTION_PARAMETERS, int gmt)
1118
1128
1119
1129
/* Clean up and return */
1120
1130
ts = timelib_date_to_int (now , & error );
1131
+ /* Seconds since epoch must fit in a zend_long */
1132
+ ZEND_ASSERT (!error );
1121
1133
ts += adjust_seconds ;
1122
1134
timelib_time_dtor (now );
1123
1135
1124
- if (error ) {
1125
- RETURN_FALSE ;
1126
- } else {
1127
- RETURN_LONG (ts );
1128
- }
1136
+ RETURN_LONG (ts );
1129
1137
}
1130
1138
/* }}} */
1131
1139
@@ -1185,7 +1193,8 @@ PHPAPI void php_strftime(INTERNAL_FUNCTION_PARAMETERS, int gmt)
1185
1193
ZEND_PARSE_PARAMETERS_END ();
1186
1194
1187
1195
if (ZSTR_LEN (format ) == 0 ) {
1188
- RETURN_FALSE ;
1196
+ zend_argument_value_error (1 , "cannot be empty" );
1197
+ RETURN_THROWS ();
1189
1198
}
1190
1199
1191
1200
if (timestamp_is_null ) {
@@ -1229,7 +1238,7 @@ PHPAPI void php_strftime(INTERNAL_FUNCTION_PARAMETERS, int gmt)
1229
1238
ta .tm_zone = offset -> abbr ;
1230
1239
#endif
1231
1240
}
1232
-
1241
+ // TODO Cleanup as bug is not present anymore? (Need to update link as MS retired connect.microsoft.com)
1233
1242
/* VS2012 crt has a bug where strftime crash with %z and %Z format when the
1234
1243
initial buffer is too small. See
1235
1244
http://connect.microsoft.com/VisualStudio/feedback/details/759720/vs2012-strftime-crash-with-z-formatting-code */
@@ -2806,7 +2815,7 @@ static int php_date_modify(zval *object, char *modify, size_t modify_len) /* {{{
2806
2815
dateobj = Z_PHPDATE_P (object );
2807
2816
2808
2817
if (!(dateobj -> time )) {
2809
- php_error_docref (NULL, E_WARNING , "The DateTime object has not been correctly initialized by its constructor" );
2818
+ zend_throw_error (NULL, "The DateTime object has not been correctly initialized by its constructor" );
2810
2819
return 0 ;
2811
2820
}
2812
2821
@@ -3382,11 +3391,9 @@ PHP_FUNCTION(date_timestamp_get)
3382
3391
timelib_update_ts (dateobj -> time , NULL );
3383
3392
3384
3393
timestamp = timelib_date_to_int (dateobj -> time , & error );
3385
- if (error ) {
3386
- RETURN_FALSE ;
3387
- } else {
3388
- RETVAL_LONG (timestamp );
3389
- }
3394
+ /* Seconds since epoch must fit in a zend_long */
3395
+ ZEND_ASSERT (!error );
3396
+ RETURN_LONG (timestamp );
3390
3397
}
3391
3398
/* }}} */
3392
3399
@@ -3457,6 +3464,11 @@ PHP_FUNCTION(timezone_open)
3457
3464
Z_PARAM_STR (tz )
3458
3465
ZEND_PARSE_PARAMETERS_END ();
3459
3466
3467
+ if (ZSTR_LEN (tz ) != strlen (ZSTR_VAL (tz ))) {
3468
+ zend_argument_value_error (1 , "cannot contain nul bytes" );
3469
+ RETURN_THROWS ();
3470
+ }
3471
+
3460
3472
tzobj = Z_PHPTIMEZONE_P (php_date_instantiate (date_ce_timezone , return_value ));
3461
3473
if (SUCCESS != timezone_initialize (tzobj , ZSTR_VAL (tz ), ZSTR_LEN (tz ))) {
3462
3474
zval_ptr_dtor (return_value );
@@ -3478,6 +3490,11 @@ PHP_METHOD(DateTimeZone, __construct)
3478
3490
Z_PARAM_STR (tz )
3479
3491
ZEND_PARSE_PARAMETERS_END ();
3480
3492
3493
+ if (ZSTR_LEN (tz ) != strlen (ZSTR_VAL (tz ))) {
3494
+ zend_argument_value_error (1 , "cannot contain nul bytes" );
3495
+ RETURN_THROWS ();
3496
+ }
3497
+
3481
3498
zend_replace_error_handling (EH_THROW , NULL , & error_handling );
3482
3499
tzobj = Z_PHPTIMEZONE_P (ZEND_THIS );
3483
3500
timezone_initialize (tzobj , ZSTR_VAL (tz ), ZSTR_LEN (tz ));
@@ -4408,6 +4425,7 @@ PHP_FUNCTION(timezone_identifiers_list)
4408
4425
4409
4426
/* Extra validation */
4410
4427
if (what == PHP_DATE_TIMEZONE_PER_COUNTRY && option_len != 2 ) {
4428
+ // Promoto to ValueError?
4411
4429
php_error_docref (NULL , E_NOTICE , "A two-letter ISO 3166-1 compatible country code is expected" );
4412
4430
RETURN_FALSE ;
4413
4431
}
0 commit comments