From a17dd5628fa9bf8734f4ee9c74f78d75e46c638a Mon Sep 17 00:00:00 2001 From: Matthew Cline Date: Tue, 13 Oct 2009 02:07:43 -0700 Subject: Bug 2877419: do error checking on autoinscribe initfile lines, to prevent the game from crashing. --- crawl-ref/source/initfile.cc | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'crawl-ref/source/initfile.cc') diff --git a/crawl-ref/source/initfile.cc b/crawl-ref/source/initfile.cc index 561cbeb645..fe3d8adcb4 100644 --- a/crawl-ref/source/initfile.cc +++ b/crawl-ref/source/initfile.cc @@ -2579,7 +2579,48 @@ void game_options::read_option_line(const std::string &str, bool runscript) } else if (key == "autoinscribe") { + if (field.empty()) + { + crawl_state.add_startup_error("Autoinscirbe string is empty"); + return; + } + + const size_t first = field.find_first_of(':'); + const size_t last = field.find_last_of(':'); + if (first == std::string::npos || first != last) + { + crawl_state.add_startup_error( + make_stringf("Autoinscribe string must have exactly " + "one colon: %s\n", field.c_str())); + return; + } + + if (first == 0) + { + crawl_state.add_startup_error( + make_stringf("Autoinscribe pattern is empty: %s\n", + field.c_str())); + return; + } + + if (last == field.length() - 1) + { + crawl_state.add_startup_error( + make_stringf("Autoinscribe result is empty: %s\n", + field.c_str())); + return; + } + std::vector thesplit = split_string(":", field); + + if (thesplit.size() != 2) + { + crawl_state.add_startup_error( + make_stringf("Error parsing autoinscribe string: %s\n", + field.c_str())); + return; + } + autoinscriptions.push_back( std::pair(thesplit[0], thesplit[1])); } -- cgit v1.2.3-54-g00ecf