From d94424f2e209b906efb0cbf50706bf8db4da861e Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Wed, 11 Oct 2023 00:52:21 +0300 Subject: [PATCH 27/27] 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 e1edb0b0d9..d410473a01 100644 --- a/common/player.c +++ b/common/player.c @@ -481,7 +481,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) { @@ -489,7 +489,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; @@ -497,7 +497,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 59a534e3be..a5f22372b8 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