From fc7fe4b31f5bd10acfdf26bb2229468424983b1d Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Wed, 11 Oct 2023 00:55:03 +0300 Subject: [PATCH 9/9] Fix player_new() NULL dereference See osdn #48624 Signed-off-by: Marko Lindqvist --- common/player.c | 8 +++++--- common/team.c | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/common/player.c b/common/player.c index 3c0c155e50..1e05c2f3d3 100644 --- a/common/player.c +++ b/common/player.c @@ -482,7 +482,7 @@ int player_slot_max_used_number(void) /**************************************************************************** Creates a new player for the slot. If slot is NULL, it will lookup to a - free slot. If the slot already used, then just return the player. + free slot. If the slot is already used, then just return the player. ****************************************************************************/ struct player *player_new(struct player_slot *pslot) { @@ -490,7 +490,7 @@ struct player *player_new(struct player_slot *pslot) fc_assert_ret_val(player_slots_initialised(), NULL); - if (NULL == pslot) { + if (pslot == NULL) { player_slots_iterate(aslot) { if (!player_slot_is_used(aslot)) { pslot = aslot; @@ -498,7 +498,9 @@ struct player *player_new(struct player_slot *pslot) } } player_slots_iterate_end; - fc_assert_ret_val(NULL != pslot, NULL); + if (pslot == NULL) { + return NULL; + } } else if (NULL != pslot->player) { return pslot->player; } diff --git a/common/team.c b/common/team.c index 0195036a11..38bfd62e46 100644 --- a/common/team.c +++ b/common/team.c @@ -312,7 +312,7 @@ void team_slot_set_defined_name(struct team_slot *tslot, /**************************************************************************** Creates a new team for the slot. If slot is NULL, it will lookup to a - free slot. If the slot already used, then just return the team. + free slot. If the slot is already used, then just return the team. ****************************************************************************/ struct team *team_new(struct team_slot *tslot) { -- 2.42.0