Removed old copy-paste error

Put numdie bounds check in croak to prevent OOB access on negative
numdie while preserving tests
This commit is contained in:
NHOrus 2017-09-05 17:46:38 +03:00
parent e5a0c6e2b7
commit 0dd40bba32
2 changed files with 6 additions and 5 deletions

3
main.c
View file

@ -85,7 +85,6 @@ int main(int argc, char *argv[])
fprintf(stderr, fprintf(stderr,
"advent: can't open save file %s for read\n", "advent: can't open save file %s for read\n",
optarg); optarg);
signal(SIGINT, sig_handler);
break; break;
#endif #endif
default: default:
@ -461,6 +460,8 @@ static bool dwarfmove(void)
static void croak(void) static void croak(void)
/* Okay, he's dead. Let's get on with it. */ /* Okay, he's dead. Let's get on with it. */
{ {
if (game.numdie < 0)
game.numdie = 0;
const char* query = obituaries[game.numdie].query; const char* query = obituaries[game.numdie].query;
const char* yes_response = obituaries[game.numdie].yes_response; const char* yes_response = obituaries[game.numdie].yes_response;
++game.numdie; ++game.numdie;

View file

@ -146,9 +146,9 @@ bool is_valid(struct game_t valgame)
} }
/* Bounds check for locations */ /* Bounds check for locations */
if ( valgame.chloc < -1 || valgame.chloc > NLOCATIONS || if ( valgame.chloc < -1 || valgame.chloc > NLOCATIONS ||
valgame.chloc2 < -1 || valgame.chloc2 > NLOCATIONS || valgame.chloc2 < -1 || valgame.chloc2 > NLOCATIONS ||
valgame.loc < -1 || valgame.loc > NLOCATIONS || valgame.loc < -1 || valgame.loc > NLOCATIONS ||
valgame.newloc < -1 || valgame.newloc > NLOCATIONS || valgame.newloc < -1 || valgame.newloc > NLOCATIONS ||
valgame.oldloc < -1 || valgame.oldloc > NLOCATIONS || valgame.oldloc < -1 || valgame.oldloc > NLOCATIONS ||
valgame.oldlc2 < -1 || valgame.oldlc2 > NLOCATIONS) { valgame.oldlc2 < -1 || valgame.oldlc2 > NLOCATIONS) {
@ -171,7 +171,7 @@ bool is_valid(struct game_t valgame)
/* Bounds check for dwarves */ /* Bounds check for dwarves */
if (valgame.dtotal < 0 || valgame.dtotal > NDWARVES || if (valgame.dtotal < 0 || valgame.dtotal > NDWARVES ||
valgame.dkill < 0 || valgame.dkill > NDWARVES) { valgame.dkill < 0 || valgame.dkill > NDWARVES) {
return false; return false;
} }