Make WordPress Core

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#17840 closed defect (bug) (fixed)

Fatal Error on General Settings when Timezone string is invalid.

Reported by: westi Owned by: westi
Milestone: 3.2 Priority: high
Severity: normal Version: 3.2
Component: Date/Time Keywords: i18n-change
Focuses: Cc:


If an enterprising user manages to get an invalid value in this option the General Settings page is completely broken:

[19-Jun-2011 08:03:27] PHP Fatal error:  Uncaught exception 'Exception' with message 'DateTimeZone::__construct() [<a href='datetimezone.--construct'>datetimezone.--construct</a>]: Unknown or bad timezone (Garbage)' in .../wp-admin/options-general.php:187Stack trace:
#0 .../wp-admin/options-general.php(187): DateTimeZone->__construct('Garbage')#1 {main}
  thrown in .../wp-admin/options-general.php on line 187

Attachments (1)

timezone.diff (2.0 KB) - added by westi 7 years ago.
Fix the Fatal Error and sanitize the option on save in future

Download all attachments as: .zip

Change History (7)

7 years ago

Fix the Fatal Error and sanitize the option on save in future

#1 @westi
7 years ago

Note with the above fix the user who has set the dodgy data still gets these Warnings and Notices:

    WARNING: wp-includes/functions.php:4082 - timezone_open() [function.timezone-open]: Unknown or bad timezone (Garbage)
    WARNING: wp-includes/functions.php:126 - timezone_open() [function.timezone-open]: Unknown or bad timezone (Garbage)
    WARNING: wp-includes/functions.php:127 - date_create() expects parameter 2 to be DateTimeZone, boolean given
    WARNING: wp-includes/functions.php:130 - date_format() expects parameter 1 to be DateTime, boolean given

    NOTICE: wp-admin/options-general.php:176 - date_default_timezone_set() [function.date-default-timezone-set]: Timezone ID 'Garbage' is invalid

I would be happy to leave fixing these till 3.3 :)

#2 @westi
7 years ago

Also note in theory a valid timezone could become invalid in future if it disappears from the map :)

#3 @ryan
7 years ago

Inserted invalid timezone string. Verified that the patched options-general.php avoid the fatal error. Selected valid timezones and verified they were properly saved. Looks good.

#4 @westi
7 years ago

  • Resolution set to fixed
  • Status changed from new to closed

In [18323]:

Ensure we have a valid timezone identifier before trying to use it.
Validate the new timezone identifier during option update.
Fixes #17840.

#5 follow-up: @nacin
7 years ago

  • Keywords i18n-change added

Bad westi :-)

#6 in reply to: ↑ 5 @westi
7 years ago

Replying to nacin:

Bad westi :-)

Good Catch.

Note: See TracTickets for help on using tickets.