任务单 #45893

city_create_unit() segfaults when punit is null

开放日期: 2022-10-17 20:58 最后更新: 2023-06-12 03:23

报告人:
(匿名)
属主:
类型:
状态:
关闭
组件:
优先:
5 - Medium
严重性:
5 - Medium
处理结果:
Fixed
文件:
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;

任务单历史 (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 (无) to cazfi
  • 处理结果 Update from to Accepted
  • 里程碑 Update from (无) to 3.1.0-beta3 (关闭)
  • 组件 Update from (无) to Server
  • 类型 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
  • 状态 Update from 开启 to 关闭
  • 处理结果 Update from Accepted to Fixed

编辑

Please login to add comment to this ticket » 登录名