opentibiabr / canary

Canary Server 13.x for OpenTibia community.
https://docs.opentibiabr.com/
GNU General Public License v2.0
384 stars 637 forks source link

fix: transfer house crash #3104

Closed dudantas closed 2 weeks ago

dudantas commented 2 weeks ago

Description

This addresses an issue in the House::resetTransferItem function where the transferItem pointer was being set to nullptr before being used later in the function, leading to potential undefined behavior or crashes. The solution involves reordering the operations to ensure that transferItem is only set to nullptr after all required operations are completed. This change ensures that the object remains accessible until all necessary manipulations are performed.

Fixes this crash: crash house.txt

Behaviour

Actual

When transferItem is set to nullptr before the removal of the item, attempting to use the tmpItem reference leads to undefined behavior or a crash because the reference is pointing to a nullptr.

Expected

transferItem should only be set to nullptr after tmpItem is fully utilized to remove the item from transfer_container. This avoids dereferencing a nullptr and ensures that operations on the item are safe.

Type of change

The change was tested by:

Checklist

sonarcloud[bot] commented 2 weeks ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarQube Cloud