backwpup icon indicating copy to clipboard operation
backwpup copied to clipboard

Fix countable error in Destination S3

Open joebailey26 opened this issue 1 year ago • 0 comments

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).
  • [x] 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.
  • [x] 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

  • [x] I wrote a self-explanatory code about what it does.
  • [ ] I protected entry points against unexpected inputs.
  • [x] 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.)

joebailey26 avatar Oct 03 '24 20:10 joebailey26