Bug #1646
openFixed a SIGSEGV in unit_order_list_is_sane()
0%
Description
For various reasons, during the save or load of a game file, if a unit's action list is rejected, the process will delete the working memory for the unit's "order's list" and set the order's list pointer to NULL.
Later, the 'data sanity check' accesses the NULL memory pointer and throws a SIGSEGV exception.
The proposed fix performs the following:- adds a guard against the use of the NULL pointer. But returns TRUE for sanity, as the list is empty.
- provides additional cleanup by zeroing out the length value in the 'orders' structure. Note: zeroing out the length would have avoided the NULL memory access, but still leaves the 'sanity' ambiguous.
- avoid the 'sanity' check on empty (NULL) order action lists for the unit. Note, the `punit->has_orders` could be refactored to only use the `puint->orders.length == 0`.
Files
Updated by John Robertson 4 days ago
- File 1646.patch 1646.patch added
Please review the proposed patch and recommend revisions as needed.
Updated by John Robertson 4 days ago
The NULL check could be considered unnecessary, as the [now reliable] `orders.length 0` would suffice to both prevent access to the NULL pointer and default to returning sanity TRUE.
Updated by John Robertson 4 days ago
- File 1646.v2.patch 1646.v2.patch added
Outside of the save/load game from file, the `punit->goto_tile` is cleared when the `punit->orders.list` and `punit->has_orders` are cleared. Replacement patch candidate clears the `punit->goto_tile` when clearing the unit's orders.
(With the `punit->orders.length` being cleared, the `orders == NULL` sanity check is redundant and removed.)
Updated by Marko Lindqvist 4 days ago
Not necessary, but you may want to do the patch with 'git format-patch' instead of just 'git diff' to include meta information like your authorship over the patch. https://www.freeciv.org/wiki/How_to_Contribute#How_to_create_patch_file_with_Git
Updated by Marko Lindqvist 2 days ago
- Status changed from New to In Review
- Assignee changed from John Robertson to Marko Lindqvist