e107inc / e107

e107 Bootstrap CMS (Content Management System) v2 with PHP, MySQL, HTML5, jQuery and Twitter Bootstrap. Issue Discussion Room: https://gitter.im/e107inc/e107
https://e107.org
GNU General Public License v3.0
320 stars 214 forks source link

Fix #5025: Type error when sending a PM without the attachment field #5027

Closed Deltik closed 1 year ago

Deltik commented 1 year ago

Motivation and Context

There is a bug where the pm plugin would return fatally error in PHP 8.2 if the user doesn't have permission to add an attachment when sending a private message. This error is due to the fact that the code expects $_FILES['file_userfile'] to be an array, but this array will not be present if the user doesn't have permission to add an attachment.

Fixes #5025

Description

This change adds a check before trying to iterate through $_FILES['file_userfile'], ensuring that it is an array before processing the attachment. If this is not an array, then no actions will be taken on $_FILES['file_userfile'], which avoids the TypeError.

How Has This Been Tested?

The fix was manually tested in a local development environment with PHP 8.2 by sending PMs with and without the attachment permission.

Types of Changes

Checklist

codeclimate[bot] commented 1 year ago

Code Climate has analyzed commit 5196c4f5 and detected 0 issues on this pull request.

The test coverage on the diff in this pull request is 0.0% (80% is the threshold).

This pull request will bring the total coverage in the repository to 34.5% (-0.2% change).

View more on Code Climate.

CaMer0n commented 1 year ago

Thank you @Deltik !