Make WordPress Core

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#51011 closed defect (bug) (fixed)

Empty string comparison on home option during DB upgrades is invalid

Reported by: fjarrett's profile fjarrett Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 5.5.1 Priority: normal
Severity: minor Version: 5.5
Component: Upgrade/Install Keywords:
Focuses: Cc:

Description

The private __get_option() function used during database upgrades was recently changed in WordPress 5.5 to use a strict comparison operator to check whether the home option value is empty string. However, wpdb::get_var returns NULL if the option is empty, so this condition never actually exists.

https://github.com/WordPress/WordPress/blob/537fd931bc02e6e934a2d774422b897871aa87ad/wp-admin/includes/upgrade.php#L2570

This was discovered because of an oddity that manifested when using WP-CLI to run database upgrades on sites that has an empty home option, and it was only reproducible with WordPress 5.5. Full discussion can be found in the #cli Slack.

https://wordpress.slack.com/archives/C02RP4T41/p1597352867393200

Some possible solutions are:

  1. Correct the strict comparison to use null === $option
  2. Use a more generous empty comparison like ! $option
  3. Refactor __get_option() to use wpdb::get_col like its get_option() cousin

---

The WP-CLI oddity is fairly easy to reproduce:

  1. Empty the home option value in the WordPress database:
$ wp db query "UPDATE wp_options SET option_value = '' WHERE option_name = 'home';"

Note: wp option update home '' won't work because the core fallback to siteurl prevents it.

  1. Set the db_version option to anything less than 48748:
$ wp option update db_version 47018
Success: Updated 'db_version' option.
  1. Execute the database update:
$ wp core update-db
Success: WordPress database upgraded successfully from db version 47018 to 48748.
  1. Check the option value:
$ wp option get home
http://http://example.com

Attachments (1)

51011.diff (549 bytes) - added by fjarrett 4 years ago.
Use null for strict comparison of home option value

Download all attachments as: .zip

Change History (10)

@fjarrett
4 years ago

Use null for strict comparison of home option value

This ticket was mentioned in Slack in #cli by fjarrett. View the logs.


4 years ago

#2 @SergeyBiryukov
4 years ago

  • Milestone changed from Awaiting Review to 5.5.1

#3 @SergeyBiryukov
4 years ago

  • Owner set to SergeyBiryukov
  • Status changed from new to reviewing

This ticket was mentioned in Slack in #hosting-community by mike. View the logs.


4 years ago

This ticket was mentioned in Slack in #core by audrasjb. View the logs.


4 years ago

#6 @johnbillion
4 years ago

Introduced in [47584].

#7 @SergeyBiryukov
4 years ago

Just noting [47584] seems unrelated, this was introduced in [47808].

#8 @SergeyBiryukov
4 years ago

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

In 48868:

Upgrade/Install: Make the check for empty home option in __get_option() more resilient.

This addresses a regression in [47808], where the home check expected an empty string to use siteurl as a fallback, but wpdb::get_var() returns null if the option is empty.

Props fjarrett.
Fixes #51011.

#9 @SergeyBiryukov
4 years ago

In 48869:

Upgrade/Install: Make the check for empty home option in __get_option() more resilient.

This addresses a regression in [47808], where the home check expected an empty string to use siteurl as a fallback, but wpdb::get_var() returns null if the option is empty.

Props fjarrett.
Merges [48868] to the 5.5 branch.
Fixes #51011.

Note: See TracTickets for help on using tickets.