fgets() fails on read error or EOF. When it fails, it doesn't touch
the buffer. Since files didn't check its return value, it read an
uninitialized character from the buffer. If that happened to be 'y'
or 'Y', it happily clobbered the game.
printf("WARNING: this blasts the existing game in %s (if any)\n",
gamedir);
printf("continue? ");
- fgets(buf, sizeof(buf), stdin);
- if (*buf != 'y' && *buf != 'Y')
+ if (!fgets(buf, sizeof(buf), stdin) || (*buf != 'y' && *buf != 'Y'))
exit(1);
}
for (i = 0; i < EF_MAX; i++) {