Ticket #45893

city_create_unit() segfaults when punit is null

Date d'ouverture: 2022-10-17 20:58 Dernière mise à jour: 2023-06-12 03:23

Rapporteur:
(Anonyme)
Propriétaire:
Type:
État:
Atteints
Composant:
Priorité:
5 - moyen
Sévérité:
5 - moyen
Résolution:
Fixed
Fichier:
1

Détails

This wasn't caught before because it's very rare. However, there may be ways to get units which are null in some situations like multiple build slots, etc. FCW server experienced it and had to fix it.

  1. static struct unit *city_create_unit(struct city *pcity,
  2. const struct unit_type *utype)
  3. {
  4. if (!pcity || !utype) return NULL; // 17Oct2022 attempt to avoid segfault
  5. struct player *pplayer = city_owner(pcity);
  6. struct unit *punit;
  7. int saved_unit_id;
  8. city_production_unit_veteran_level(pcity, utype),
  9. pcity->id, 0);
  10. pplayer->score.units_built++;
  11. if (!punit) {
  12. notify_conn(game.est_connections, city_tile(pcity),
  13. E_WONDER_WILL_BE_BUILT, ftc_server,
  14. _("Notice: %s in %s creating illegal segfault. Report to admin immediately!"),
  15. utype_name_translation(utype),
  16. city_link(pcity));
  17. return NULL; // 17Oct2022 line below was segfault:
  18. }
  19. saved_unit_id = punit->id;

Ticket History (3/5 Histories)

2022-10-17 20:58 Updated by: None
  • New Ticket "city_create_unit() segfaults when punit is null" created
2022-10-17 21:35 Updated by: cazfi
Commentaire

Reply To (Anonymous)

This wasn't caught before because it's very rare. However, there may be ways to get units which are null in some situations like multiple build slots, etc. FCW server experienced it and had to fix it.

Those cases with multiple build slots producing NULL units seem like result of FCW specific bugs #45894 and #45895

2023-06-09 07:36 Updated by: cazfi
  • Propriétaire Update from (Aucun) to cazfi
  • Résolution Update from Aucun to Accepted
  • Jalon Update from (Aucun) to 3.1.0-beta3 (atteints)
  • Composant Update from (Aucun) to Server
  • Type Update from Bogues to Patches
Commentaire

Reply To cazfi

Those cases with multiple build slots producing NULL units seem like result of FCW specific bugs #45894 and #45895

Attached patch gives those parameters nonnull attribute, to make it likely that in the future such bugs get caught as soon as they get created.

2023-06-12 03:23 Updated by: cazfi
  • État Update from Ouvert to Atteints
  • Résolution Update from Accepted to Fixed

Modifier

Please login to add comment to this ticket » Connexion