mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-21 16:05:44 -07:00
Validate that save file values are ASCII (mostly)
Apart from "SEED" records, all values in save files generated by Puzzles should be printable ASCII. This is enforced by assertion in the saving code. However, if a save file with non-ASCII move strings (for instance) manages to get loaded then these non-ASCII values can cause an assertion failure on saving. Instead, the loading code now checks values for ASCIIness. This will not only avoid problems when re-saving files, but will also defend the various internal parsers from at least some evil strings. It shouldn't invalidate any save files actually generated by Puzzles, but it will sadly invalidate some of my fuzzing corpus.
This commit is contained in:
7
midend.c
7
midend.c
@ -2329,6 +2329,13 @@ static const char *midend_deserialise_internal(
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
val[len] = '\0';
|
val[len] = '\0';
|
||||||
|
/* Validate that all values (apart from SEED) are printable ASCII. */
|
||||||
|
if (strcmp(key, "SEED"))
|
||||||
|
for (i = 0; val[i]; i++)
|
||||||
|
if (val[i] < 32 || val[i] >= 127) {
|
||||||
|
ret = "Forbidden characters in saved game file";
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
if (!started) {
|
if (!started) {
|
||||||
if (strcmp(key, "SAVEFILE") || strcmp(val, SERIALISE_MAGIC)) {
|
if (strcmp(key, "SAVEFILE") || strcmp(val, SERIALISE_MAGIC)) {
|
||||||
|
Reference in New Issue
Block a user