@@ -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
}
@@ -951,8 +951,8 @@ PHP_FUNCTION(idate)
951
951
ZEND_PARSE_PARAMETERS_END ();
952
952
953
953
if (ZSTR_LEN (format ) != 1 ) {
954
- php_error_docref ( NULL , E_WARNING , "idate format is one char " );
955
- RETURN_FALSE ;
954
+ zend_argument_value_error ( 1 , "must be one character " );
955
+ RETURN_THROWS () ;
956
956
}
957
957
958
958
if (ts_is_null ) {
@@ -961,8 +961,8 @@ 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. " );
965
- RETURN_FALSE ;
964
+ zend_argument_value_error ( 1 , "must be a valid date format token" );
965
+ RETURN_THROWS () ;
966
966
}
967
967
RETURN_LONG (ret );
968
968
}
@@ -1022,6 +1022,12 @@ 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
+ /* TODO Add a Warning? */
1028
+ RETURN_FALSE ;
1029
+ }
1030
+
1025
1031
tzi = get_timezone_info ();
1026
1032
1027
1033
now = timelib_time_ctor ();
@@ -1034,18 +1040,26 @@ PHP_FUNCTION(strtotime)
1034
1040
DATE_TIMEZONEDB , php_date_parse_tzfile_wrapper );
1035
1041
error1 = error -> error_count ;
1036
1042
timelib_error_container_dtor (error );
1043
+ if (error1 ) {
1044
+ timelib_time_dtor (now );
1045
+ timelib_time_dtor (t );
1046
+ RETURN_FALSE ;
1047
+ }
1048
+
1037
1049
timelib_fill_holes (t , now , TIMELIB_NO_CLONE );
1038
1050
timelib_update_ts (t , tzi );
1039
1051
ts = timelib_date_to_int (t , & error2 );
1040
1052
1041
1053
timelib_time_dtor (now );
1042
1054
timelib_time_dtor (t );
1043
1055
1044
- if (error1 || error2 ) {
1056
+ /* Seconds since epoch must fit in a zend_long */
1057
+ if (error2 ) {
1058
+ /* TODO Add warning? */
1045
1059
RETURN_FALSE ;
1046
- } else {
1047
- RETURN_LONG (ts );
1048
1060
}
1061
+
1062
+ RETURN_LONG (ts );
1049
1063
}
1050
1064
/* }}} */
1051
1065
@@ -1116,14 +1130,18 @@ PHPAPI void php_mktime(INTERNAL_FUNCTION_PARAMETERS, int gmt)
1116
1130
1117
1131
/* Clean up and return */
1118
1132
ts = timelib_date_to_int (now , & error );
1119
- ts += adjust_seconds ;
1120
- timelib_time_dtor (now );
1121
1133
1134
+ /* Seconds since epoch must fit in a zend_long */
1122
1135
if (error ) {
1136
+ timelib_time_dtor (now );
1137
+ /* TODO Add warning? */
1123
1138
RETURN_FALSE ;
1124
- } else {
1125
- RETURN_LONG (ts );
1126
1139
}
1140
+
1141
+ ts += adjust_seconds ;
1142
+ timelib_time_dtor (now );
1143
+
1144
+ RETURN_LONG (ts );
1127
1145
}
1128
1146
/* }}} */
1129
1147
@@ -1180,6 +1198,7 @@ PHPAPI void php_strftime(INTERNAL_FUNCTION_PARAMETERS, int gmt)
1180
1198
ZEND_PARSE_PARAMETERS_END ();
1181
1199
1182
1200
if (ZSTR_LEN (format ) == 0 ) {
1201
+ /* TODO Add a warning? */
1183
1202
RETURN_FALSE ;
1184
1203
}
1185
1204
@@ -1224,7 +1243,7 @@ PHPAPI void php_strftime(INTERNAL_FUNCTION_PARAMETERS, int gmt)
1224
1243
ta .tm_zone = offset -> abbr ;
1225
1244
#endif
1226
1245
}
1227
-
1246
+ // TODO Cleanup as bug is not present anymore? (Need to update link as MS retired connect.microsoft.com)
1228
1247
/* VS2012 crt has a bug where strftime crash with %z and %Z format when the
1229
1248
initial buffer is too small. See
1230
1249
http://connect.microsoft.com/VisualStudio/feedback/details/759720/vs2012-strftime-crash-with-z-formatting-code */
@@ -2781,7 +2800,7 @@ static int php_date_modify(zval *object, char *modify, size_t modify_len) /* {{{
2781
2800
dateobj = Z_PHPDATE_P (object );
2782
2801
2783
2802
if (!(dateobj -> time )) {
2784
- php_error_docref (NULL , E_WARNING , "The DateTime object has not been correctly initialized by its constructor" );
2803
+ zend_throw_error (NULL , "The DateTime object has not been correctly initialized by its constructor" );
2785
2804
return 0 ;
2786
2805
}
2787
2806
@@ -3319,11 +3338,14 @@ PHP_FUNCTION(date_timestamp_get)
3319
3338
timelib_update_ts (dateobj -> time , NULL );
3320
3339
3321
3340
timestamp = timelib_date_to_int (dateobj -> time , & error );
3341
+
3342
+ /* Seconds since epoch must fit in a zend_long */
3322
3343
if (error ) {
3344
+ /* TODO Add warning? */
3323
3345
RETURN_FALSE ;
3324
- } else {
3325
- RETVAL_LONG (timestamp );
3326
3346
}
3347
+
3348
+ RETURN_LONG (timestamp );
3327
3349
}
3328
3350
/* }}} */
3329
3351
@@ -3387,7 +3409,7 @@ PHP_FUNCTION(timezone_open)
3387
3409
php_timezone_obj * tzobj ;
3388
3410
3389
3411
ZEND_PARSE_PARAMETERS_START (1 , 1 )
3390
- Z_PARAM_STR (tz )
3412
+ Z_PARAM_PATH_STR (tz ) /* To prevent nul bytes */
3391
3413
ZEND_PARSE_PARAMETERS_END ();
3392
3414
3393
3415
tzobj = Z_PHPTIMEZONE_P (php_date_instantiate (date_ce_timezone , return_value ));
@@ -3406,7 +3428,7 @@ PHP_METHOD(DateTimeZone, __construct)
3406
3428
zend_error_handling error_handling ;
3407
3429
3408
3430
ZEND_PARSE_PARAMETERS_START (1 , 1 )
3409
- Z_PARAM_STR (tz )
3431
+ Z_PARAM_PATH_STR (tz ) /* To prevent nul bytes */
3410
3432
ZEND_PARSE_PARAMETERS_END ();
3411
3433
3412
3434
zend_replace_error_handling (EH_THROW , NULL , & error_handling );
@@ -4336,6 +4358,7 @@ PHP_FUNCTION(timezone_identifiers_list)
4336
4358
4337
4359
/* Extra validation */
4338
4360
if (what == PHP_DATE_TIMEZONE_PER_COUNTRY && option_len != 2 ) {
4361
+ // Promoto to ValueError?
4339
4362
php_error_docref (NULL , E_NOTICE , "A two-letter ISO 3166-1 compatible country code is expected" );
4340
4363
RETURN_FALSE ;
4341
4364
}
0 commit comments