@@ -3968,24 +3968,18 @@ PHP_FUNCTION(date_diff)
3968
3968
}
3969
3969
/* }}} */
3970
3970
3971
- static bool timezone_initialize (php_timezone_obj * tzobj , const char * tz , size_t tz_len , char * * warning_message ) /* {{{ */
3971
+ static bool timezone_initialize (php_timezone_obj * tzobj , const zend_string * tz_zstr , char * * warning_message ) /* {{{ */
3972
3972
{
3973
3973
timelib_time * dummy_t = ecalloc (1 , sizeof (timelib_time ));
3974
3974
int dst , not_found ;
3975
- const char * orig_tz = tz ;
3975
+ const char * tz = ZSTR_VAL ( tz_zstr ) ;
3976
3976
3977
- if (strlen (tz ) != tz_len ) {
3978
- if (warning_message ) {
3979
- spprintf (warning_message , 0 , "Timezone must not contain null bytes" );
3980
- }
3981
- efree (dummy_t );
3982
- return false;
3983
- }
3977
+ ZEND_ASSERT (!zend_str_has_nul_byte (tz_zstr ) && "timezone should have been checked to not have null bytes" );
3984
3978
3985
3979
dummy_t -> z = timelib_parse_zone (& tz , & dst , dummy_t , & not_found , DATE_TIMEZONEDB , php_date_parse_tzfile_wrapper );
3986
3980
if ((dummy_t -> z >= (100 * 60 * 60 )) || (dummy_t -> z <= (-100 * 60 * 60 ))) {
3987
3981
if (warning_message ) {
3988
- spprintf (warning_message , 0 , "Timezone offset is out of range (%s)" , orig_tz );
3982
+ spprintf (warning_message , 0 , "Timezone offset is out of range (%s)" , ZSTR_VAL ( tz_zstr ) );
3989
3983
}
3990
3984
timelib_free (dummy_t -> tz_abbr );
3991
3985
efree (dummy_t );
@@ -3994,15 +3988,15 @@ static bool timezone_initialize(php_timezone_obj *tzobj, const char *tz, size_t
3994
3988
dummy_t -> dst = dst ;
3995
3989
if (!not_found && (* tz != '\0' )) {
3996
3990
if (warning_message ) {
3997
- spprintf (warning_message , 0 , "Unknown or bad timezone (%s)" , orig_tz );
3991
+ spprintf (warning_message , 0 , "Unknown or bad timezone (%s)" , ZSTR_VAL ( tz_zstr ) );
3998
3992
}
3999
3993
timelib_free (dummy_t -> tz_abbr );
4000
3994
efree (dummy_t );
4001
3995
return false;
4002
3996
}
4003
3997
if (not_found ) {
4004
3998
if (warning_message ) {
4005
- spprintf (warning_message , 0 , "Unknown or bad timezone (%s)" , orig_tz );
3999
+ spprintf (warning_message , 0 , "Unknown or bad timezone (%s)" , ZSTR_VAL ( tz_zstr ) );
4006
4000
}
4007
4001
efree (dummy_t );
4008
4002
return false;
@@ -4026,7 +4020,7 @@ PHP_FUNCTION(timezone_open)
4026
4020
ZEND_PARSE_PARAMETERS_END ();
4027
4021
4028
4022
tzobj = Z_PHPTIMEZONE_P (php_date_instantiate (date_ce_timezone , return_value ));
4029
- if (!timezone_initialize (tzobj , ZSTR_VAL ( tz ), ZSTR_LEN ( tz ) , & warning_message )) {
4023
+ if (!timezone_initialize (tzobj , tz , & warning_message )) {
4030
4024
php_error_docref (NULL , E_WARNING , "%s" , warning_message );
4031
4025
efree (warning_message );
4032
4026
zval_ptr_dtor (return_value );
@@ -4047,7 +4041,7 @@ PHP_METHOD(DateTimeZone, __construct)
4047
4041
ZEND_PARSE_PARAMETERS_END ();
4048
4042
4049
4043
tzobj = Z_PHPTIMEZONE_P (ZEND_THIS );
4050
- if (!timezone_initialize (tzobj , ZSTR_VAL ( tz ), ZSTR_LEN ( tz ) , & exception_message )) {
4044
+ if (!timezone_initialize (tzobj , tz , & exception_message )) {
4051
4045
zend_throw_exception_ex (date_ce_date_invalid_timezone_exception , 0 , "DateTimeZone::__construct(): %s" , exception_message );
4052
4046
efree (exception_message );
4053
4047
RETURN_THROWS ();
@@ -4078,7 +4072,10 @@ static bool php_date_timezone_initialize_from_hash(zval **return_value, php_time
4078
4072
if (Z_TYPE_P (z_timezone ) != IS_STRING ) {
4079
4073
return false;
4080
4074
}
4081
- return timezone_initialize (* tzobj , Z_STRVAL_P (z_timezone ), Z_STRLEN_P (z_timezone ), NULL );
4075
+ if (UNEXPECTED (zend_str_has_nul_byte (Z_STR_P (z_timezone )))) {
4076
+ return false;
4077
+ }
4078
+ return timezone_initialize (* tzobj , Z_STR_P (z_timezone ), NULL );
4082
4079
} /* }}} */
4083
4080
4084
4081
/* {{{ */
0 commit comments