diff options
author | Matthew Cline <zelgadis@sourceforge.net> | 2009-10-13 02:07:43 -0700 |
---|---|---|
committer | Matthew Cline <zelgadis@sourceforge.net> | 2009-10-13 02:07:43 -0700 |
commit | a17dd5628fa9bf8734f4ee9c74f78d75e46c638a (patch) | |
tree | e35725fba33a3b090d94776033ece559c4bb0bc1 /crawl-ref/source/initfile.cc | |
parent | 8419ed9fd356777c0028bd0e89747c51460e5045 (diff) | |
download | crawl-ref-a17dd5628fa9bf8734f4ee9c74f78d75e46c638a.tar.gz crawl-ref-a17dd5628fa9bf8734f4ee9c74f78d75e46c638a.zip |
Bug 2877419: do error checking on autoinscribe initfile lines, to
prevent the game from crashing.
Diffstat (limited to 'crawl-ref/source/initfile.cc')
-rw-r--r-- | crawl-ref/source/initfile.cc | 41 |
1 files changed, 41 insertions, 0 deletions
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<std::string> 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<text_pattern,std::string>(thesplit[0], thesplit[1])); } |