]> granicus.if.org Git - php/commitdiff
Merge branch 'PHP-7.4'
authorChristoph M. Becker <cmbecker69@gmx.de>
Mon, 30 Mar 2020 07:18:20 +0000 (09:18 +0200)
committerChristoph M. Becker <cmbecker69@gmx.de>
Mon, 30 Mar 2020 07:18:20 +0000 (09:18 +0200)
* PHP-7.4:
  Fix #74940: DateTimeZone loose comparison always true

1  2 
ext/date/php_date.c

index edccb07c40ca0591c34af2b04e2a4694619ddf02,02068b44ccb75e5fb4ef16bfe513facb2870524f..00d7892a6a58800f235ac21ea7c6cb4a9b4b0209
@@@ -335,13 -673,15 +335,15 @@@ static HashTable *date_object_get_debug
  static void php_timezone_to_string(php_timezone_obj *tzobj, zval *zv);
  
  static int date_interval_compare_objects(zval *o1, zval *o2);
 -static zval *date_interval_read_property(zval *object, zval *member, int type, void **cache_slot, zval *rv);
 -static zval *date_interval_write_property(zval *object, zval *member, zval *value, void **cache_slot);
 -static zval *date_interval_get_property_ptr_ptr(zval *object, zval *member, int type, void **cache_slot);
 -static zval *date_period_read_property(zval *object, zval *member, int type, void **cache_slot, zval *rv);
 -static zval *date_period_write_property(zval *object, zval *member, zval *value, void **cache_slot);
 -static zval *date_period_get_property_ptr_ptr(zval *object, zval *member, int type, void **cache_slot);
 +static zval *date_interval_read_property(zend_object *object, zend_string *member, int type, void **cache_slot, zval *rv);
 +static zval *date_interval_write_property(zend_object *object, zend_string *member, zval *value, void **cache_slot);
 +static zval *date_interval_get_property_ptr_ptr(zend_object *object, zend_string *member, int type, void **cache_slot);
 +static zval *date_period_read_property(zend_object *object, zend_string *name, int type, void **cache_slot, zval *rv);
 +static zval *date_period_write_property(zend_object *object, zend_string *name, zval *value, void **cache_slot);
 +static zval *date_period_get_property_ptr_ptr(zend_object *object, zend_string *name, int type, void **cache_slot);
  
+ static int date_object_compare_timezone(zval *tz1, zval *tz2);
  /* {{{ Module struct */
  zend_module_entry date_module_entry = {
        STANDARD_MODULE_HEADER_EX,
@@@ -1794,6 -2157,7 +1796,7 @@@ static void date_register_classes(void
        date_object_handlers_timezone.get_properties_for = date_object_get_properties_for_timezone;
        date_object_handlers_timezone.get_gc = date_object_get_gc_timezone;
        date_object_handlers_timezone.get_debug_info = date_object_get_debug_info_timezone;
++      date_object_handlers_timezone.compare = date_object_compare_timezone;
  
  #define REGISTER_TIMEZONE_CLASS_CONST_STRING(const_name, value) \
        zend_declare_class_constant_long(date_ce_timezone, const_name, sizeof(const_name)-1, value);
@@@ -2024,6 -2383,31 +2027,33 @@@ static zend_object *date_object_clone_t
        return &new_obj->std;
  } /* }}} */
  
+ static int date_object_compare_timezone(zval *tz1, zval *tz2) /* {{{ */
+ {
+       php_timezone_obj *o1, *o2;
++      ZEND_COMPARE_OBJECTS_FALLBACK(tz1, tz2);
++
+       o1 = Z_PHPTIMEZONE_P(tz1);
+       o2 = Z_PHPTIMEZONE_P(tz2);
+       ZEND_ASSERT(o1->initialized && o2->initialized);
+       if (o1->type != o2->type) {
+               php_error_docref(NULL, E_WARNING, "Trying to compare different kinds of DateTimeZone objects");
+               return 1;
+       }
+       switch (o1->type) {
+               case TIMELIB_ZONETYPE_OFFSET:
+                       return o1->tzi.utc_offset == o2->tzi.utc_offset ? 0 : 1;
+               case TIMELIB_ZONETYPE_ABBR:
+                       return strcmp(o1->tzi.z.abbr, o2->tzi.z.abbr) ? 1 : 0;
+               case TIMELIB_ZONETYPE_ID:
+                       return strcmp(o1->tzi.tz->name, o2->tzi.tz->name) ? 1 : 0;
+               EMPTY_SWITCH_DEFAULT_CASE();
+       }
+ } /* }}} */
  static void php_timezone_to_string(php_timezone_obj *tzobj, zval *zv)
  {
        switch (tzobj->type) {