Incidencia #45893

city_create_unit() segfaults when punit is null

Abrir Fecha: 2022-10-17 20:58 Última actualización: 2023-06-12 03:23

Informador:
(Anónimo)
Propietario:
Tipo:
Estado:
Cerrado
Componente:
Prioridad:
5 - Medium
Gravedad:
5 - Medium
Resolución:
Fixed
Fichero:
1

Details

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
Comentario

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
  • Propietario Update from (Ninguno) to cazfi
  • Resolución Update from Ninguno to Accepted
  • Hito Update from (Ninguno) to 3.1.0-beta3 (cerrado)
  • Componente Update from (Ninguno) to Server
  • Tipo Update from Bugs to Patches
Comentario

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
  • Estado Update from Open to Cerrado
  • Resolución Update from Accepted to Fixed

Editar

Please login to add comment to this ticket » Entrar