Repository navigation
Commit 52169a7
committed
Fix: signed integer overflow when mixing in server seed value.
sysopt.serverseed is a plain int filled across the full positive
range [1, INT_MAX] (the install-time generator uses v % 2147483647
and read_serverseed_file() accepts any val up to INT_MAX), so signed
arithmetic that adds to it can overflow. On a build compiled with
-fsanitize=undefined -fno-sanitize-recover=all this aborts the game
outright; a player hit it at new-game start, where any seed in
(INT_MAX - 8000000, INT_MAX] overflowed. The only real consumer,
coord_hash(), already reads the value as unsigned int, so the
overflow served no functional purpose.
* src/allmain.c: newgame() did sysopt.serverseed += rn2(8000000),
overflowing int for seeds near INT_MAX and aborting under UBSan at
new-game start. Compute the sum as unsigned and mask with
0x7fffffff so the result stays a non-negative int.
* src/shknam.c: the shopkeeper-name seed (int)((long)ubirthday/257L)
+ sysopt.serverseed had the same latent overflow. Promote the
addition to unsigned and cast back; nseed is used only via % 13
and % 5 with an existing negative-result guard, so the defined
wraparound is harmless and the non-overflowing value is unchanged.1 parent 70aea70 commit 52169a7
3 files changed
Lines changed: 8 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5470 | 5470 | | |
5471 | 5471 | | |
5472 | 5472 | | |
| 5473 | + | |
5473 | 5474 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1250 | 1250 | | |
1251 | 1251 | | |
1252 | 1252 | | |
1253 | | - | |
1254 | | - | |
| 1253 | + | |
| 1254 | + | |
| 1255 | + | |
| 1256 | + | |
| 1257 | + | |
1255 | 1258 | | |
1256 | 1259 | | |
1257 | 1260 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
514 | 514 | | |
515 | 515 | | |
516 | 516 | | |
517 | | - | |
| 517 | + | |
| 518 | + | |
518 | 519 | | |
519 | 520 | | |
520 | 521 | | |
| |||
0 commit comments