@@ -549,7 +549,7 @@ PHPAPI timelib_tzinfo *get_timezone_info(void)
549
549
tz = guess_timezone (DATE_TIMEZONEDB );
550
550
tzi = php_date_parse_tzfile (tz , DATE_TIMEZONEDB );
551
551
if (! tzi ) {
552
- php_error_docref (NULL , E_ERROR , "Timezone database is corrupt - this should * never* happen! " );
552
+ zend_throw_error (NULL , "Timezone database is corrupt. Please file a bug report as this should never happen" );
553
553
}
554
554
return tzi ;
555
555
}
@@ -950,8 +950,8 @@ PHP_FUNCTION(idate)
950
950
ZEND_PARSE_PARAMETERS_END ();
951
951
952
952
if (ZSTR_LEN (format ) != 1 ) {
953
- php_error_docref ( NULL , E_WARNING , "idate format is one char " );
954
- RETURN_FALSE ;
953
+ zend_argument_value_error ( 1 , "must be one character " );
954
+ RETURN_THROWS () ;
955
955
}
956
956
957
957
if (ts_is_null ) {
@@ -960,8 +960,8 @@ PHP_FUNCTION(idate)
960
960
961
961
ret = php_idate (ZSTR_VAL (format )[0 ], ts , 0 );
962
962
if (ret == -1 ) {
963
- php_error_docref ( NULL , E_WARNING , "Unrecognized date format token. " );
964
- RETURN_FALSE ;
963
+ zend_argument_value_error ( 1 , "must be a valid date format token" );
964
+ RETURN_THROWS () ;
965
965
}
966
966
RETURN_LONG (ret );
967
967
}
@@ -1021,6 +1021,12 @@ PHP_FUNCTION(strtotime)
1021
1021
Z_PARAM_LONG_OR_NULL (preset_ts , preset_ts_is_null )
1022
1022
ZEND_PARSE_PARAMETERS_END ();
1023
1023
1024
+ /* timelib_strtotime() expects the string to not be empty */
1025
+ if (ZSTR_LEN (times ) == 0 ) {
1026
+ /* TODO Add a Warning? */
1027
+ RETURN_FALSE ;
1028
+ }
1029
+
1024
1030
tzi = get_timezone_info ();
1025
1031
1026
1032
now = timelib_time_ctor ();
@@ -1033,18 +1039,26 @@ PHP_FUNCTION(strtotime)
1033
1039
DATE_TIMEZONEDB , php_date_parse_tzfile_wrapper );
1034
1040
error1 = error -> error_count ;
1035
1041
timelib_error_container_dtor (error );
1042
+ if (error1 ) {
1043
+ timelib_time_dtor (now );
1044
+ timelib_time_dtor (t );
1045
+ RETURN_FALSE ;
1046
+ }
1047
+
1036
1048
timelib_fill_holes (t , now , TIMELIB_NO_CLONE );
1037
1049
timelib_update_ts (t , tzi );
1038
1050
ts = timelib_date_to_int (t , & error2 );
1039
1051
1040
1052
timelib_time_dtor (now );
1041
1053
timelib_time_dtor (t );
1042
1054
1043
- if (error1 || error2 ) {
1055
+ /* Seconds since epoch must fit in a zend_long */
1056
+ if (error2 ) {
1057
+ /* TODO Add warning? */
1044
1058
RETURN_FALSE ;
1045
- } else {
1046
- RETURN_LONG (ts );
1047
1059
}
1060
+
1061
+ RETURN_LONG (ts );
1048
1062
}
1049
1063
/* }}} */
1050
1064
@@ -1115,14 +1129,18 @@ PHPAPI void php_mktime(INTERNAL_FUNCTION_PARAMETERS, int gmt)
1115
1129
1116
1130
/* Clean up and return */
1117
1131
ts = timelib_date_to_int (now , & error );
1118
- ts += adjust_seconds ;
1119
- timelib_time_dtor (now );
1120
1132
1133
+ /* Seconds since epoch must fit in a zend_long */
1121
1134
if (error ) {
1135
+ timelib_time_dtor (now );
1136
+ /* TODO Add warning? */
1122
1137
RETURN_FALSE ;
1123
- } else {
1124
- RETURN_LONG (ts );
1125
1138
}
1139
+
1140
+ ts += adjust_seconds ;
1141
+ timelib_time_dtor (now );
1142
+
1143
+ RETURN_LONG (ts );
1126
1144
}
1127
1145
/* }}} */
1128
1146
@@ -1179,6 +1197,7 @@ PHPAPI void php_strftime(INTERNAL_FUNCTION_PARAMETERS, int gmt)
1179
1197
ZEND_PARSE_PARAMETERS_END ();
1180
1198
1181
1199
if (ZSTR_LEN (format ) == 0 ) {
1200
+ /* TODO Add a warning? */
1182
1201
RETURN_FALSE ;
1183
1202
}
1184
1203
@@ -1223,7 +1242,7 @@ PHPAPI void php_strftime(INTERNAL_FUNCTION_PARAMETERS, int gmt)
1223
1242
ta .tm_zone = offset -> abbr ;
1224
1243
#endif
1225
1244
}
1226
-
1245
+ // TODO Cleanup as bug is not present anymore? (Need to update link as MS retired connect.microsoft.com)
1227
1246
/* VS2012 crt has a bug where strftime crash with %z and %Z format when the
1228
1247
initial buffer is too small. See
1229
1248
http://connect.microsoft.com/VisualStudio/feedback/details/759720/vs2012-strftime-crash-with-z-formatting-code */
@@ -2780,7 +2799,7 @@ static int php_date_modify(zval *object, char *modify, size_t modify_len) /* {{{
2780
2799
dateobj = Z_PHPDATE_P (object );
2781
2800
2782
2801
if (!(dateobj -> time )) {
2783
- php_error_docref (NULL , E_WARNING , "The DateTime object has not been correctly initialized by its constructor" );
2802
+ zend_throw_error (NULL , "The DateTime object has not been correctly initialized by its constructor" );
2784
2803
return 0 ;
2785
2804
}
2786
2805
@@ -3318,11 +3337,14 @@ PHP_FUNCTION(date_timestamp_get)
3318
3337
timelib_update_ts (dateobj -> time , NULL );
3319
3338
3320
3339
timestamp = timelib_date_to_int (dateobj -> time , & error );
3340
+
3341
+ /* Seconds since epoch must fit in a zend_long */
3321
3342
if (error ) {
3343
+ /* TODO Add warning? */
3322
3344
RETURN_FALSE ;
3323
- } else {
3324
- RETVAL_LONG (timestamp );
3325
3345
}
3346
+
3347
+ RETURN_LONG (timestamp );
3326
3348
}
3327
3349
/* }}} */
3328
3350
@@ -3386,7 +3408,7 @@ PHP_FUNCTION(timezone_open)
3386
3408
php_timezone_obj * tzobj ;
3387
3409
3388
3410
ZEND_PARSE_PARAMETERS_START (1 , 1 )
3389
- Z_PARAM_STR (tz )
3411
+ Z_PARAM_PATH_STR (tz ) /* To prevent nul bytes */
3390
3412
ZEND_PARSE_PARAMETERS_END ();
3391
3413
3392
3414
tzobj = Z_PHPTIMEZONE_P (php_date_instantiate (date_ce_timezone , return_value ));
@@ -3405,7 +3427,7 @@ PHP_METHOD(DateTimeZone, __construct)
3405
3427
zend_error_handling error_handling ;
3406
3428
3407
3429
ZEND_PARSE_PARAMETERS_START (1 , 1 )
3408
- Z_PARAM_STR (tz )
3430
+ Z_PARAM_PATH_STR (tz ) /* To prevent nul bytes */
3409
3431
ZEND_PARSE_PARAMETERS_END ();
3410
3432
3411
3433
zend_replace_error_handling (EH_THROW , NULL , & error_handling );
@@ -4321,6 +4343,7 @@ PHP_FUNCTION(timezone_identifiers_list)
4321
4343
4322
4344
/* Extra validation */
4323
4345
if (what == PHP_DATE_TIMEZONE_PER_COUNTRY && option_len != 2 ) {
4346
+ // Promoto to ValueError?
4324
4347
php_error_docref (NULL , E_NOTICE , "A two-letter ISO 3166-1 compatible country code is expected" );
4325
4348
RETURN_FALSE ;
4326
4349
}
0 commit comments