Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix countable error in Destination S3 #143

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

joebailey26
Copy link

Description

When $buckets does not contain Buckets as a key in the array, the plugin falls over as it tries to count a non-existent variable. This PR ensures that either $buckets['Buckets'] is empty, or less than 1 before throwing the No bucket found! message.

Type of change

  • New feature (non-breaking change which adds functionality).
  • Bug fix (non-breaking change which fixes an issue).
  • Enhancement (non-breaking change which improves an existing functionality).
  • Breaking change (fix or feature that would cause existing functionality to not work as before).
  • Sub-task of #(issue number)
  • Release

Detailed scenario

This error occurred after updating to 4.1.5.

WordPress version 6.6.2
Current plugin: BackWPup (version 4.1.5)
PHP version 8.3.11

Error Details
=============
An error of type E_ERROR was caused in line 526 of the file /var/www/htdocs/wp-content/plugins/backwpup/inc/class-destination-s3.php. Error message: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given in /var/www/htdocs/wp-content/plugins/backwpup/inc/class-destination-s3.php:526
Stack trace:
#0 /var/www/htdocs/wp-content/plugins/backwpup/inc/class-destination-s3.php(283): BackWPup_Destination_S3->edit_ajax(Array)
#1 /var/www/htdocs/wp-content/plugins/backwpup/inc/class-page-editjob.php(831): BackWPup_Destination_S3->edit_tab(1)
#2 /var/www/htdocs/wp-includes/class-wp-hook.php(324): BackWPup_Page_Editjob::page('')
#3 /var/www/htdocs/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters('', Array)
#4 /var/www/htdocs/wp-includes/plugin.php(517): WP_Hook->do_action(Array)
#5 /var/www/htdocs/wp-admin/admin.php(259): do_action('backwpup_page_b...')
#6 {main}
  thrown

Mandatory Checklist

Code validation

  • I validated all the Acceptance Criteria. If possible, provide screenshots or videos.
  • I triggered all changed lines of code at least once without new errors/warnings/notices.
  • I implemented built-in tests to cover the new/changed code.

Code style

  • I wrote a self-explanatory code about what it does.
  • I protected entry points against unexpected inputs.
  • I did not introduce unnecessary complexity.
  • Output messages (errors, notices, logs) are explicit enough for users to understand the issue and are actionnable.

Additional Checks

  • In the case of complex code, I wrote comments to explain it.
  • When possible, I prepared ways to observe the implemented system (logs, data, etc.).
  • I added error handling logic when using functions that could throw errors (HTTP/API request, filesystem, etc.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant