Ticket #45893

city_create_unit() segfaults when punit is null

오픈 날짜: 2022-10-17 20:58 마지막 업데이트: 2023-06-12 03:23

Reporter:
(Anonymous)
소유자:
Type:
Status:
Closed
Component:
Priority:
5 - Medium
Severity:
5 - Medium
Resolution:
Fixed
File:
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
댓글 올리기

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
  • 소유자 Update from (None) to cazfi
  • Resolution Update from None to Accepted
  • Milestone Update from (None) to 3.1.0-beta3 (closed)
  • Component Update from (None) to Server
  • Type Update from Bugs to Patches
댓글 올리기

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
  • Status Update from Open to Closed
  • Resolution Update from Accepted to Fixed

Edit

Please login to add comment to this ticket » Login