diff options
author | Neil Moore <neil@s-z.org> | 2014-04-24 23:08:33 -0400 |
---|---|---|
committer | Neil Moore <neil@s-z.org> | 2014-04-24 23:22:53 -0400 |
commit | a618dc043d2361b531413daa5232a9c533093982 (patch) | |
tree | ad58f802e4f149247d3b2cb2e33a9bc244b22e92 /crawl-ref/source/macro.cc | |
parent | 89cd1729901393a715455bbc7cd37db841a99b58 (diff) | |
download | crawl-ref-a618dc043d2361b531413daa5232a9c533093982.tar.gz crawl-ref-a618dc043d2361b531413daa5232a9c533093982.zip |
Avoid a crash parsing bad keymap lines in macro files.
If we encounter a K<char>: keymap definition with an invalid character
(not '0' through '5'), we don't set the key and don't switch to keymap
mode, but we did change the keymap context. If we were in keymap mode
already, this leads to us making an out-of-bounds access to the Keymaps
array when we later parse the A: line and try to add the macro.
Now the bad K?: line is completely ignored; this means we replace
the action of the previous map or macro, but that's better than
crashing (and happened already if the previous thing was a macro).
An example of a keymap that would cause a crash (the first line is not
necessary if another keymap immediately preceded this one):
K:x
K~:y
A:z
Diffstat (limited to 'crawl-ref/source/macro.cc')
-rw-r--r-- | crawl-ref/source/macro.cc | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/crawl-ref/source/macro.cc b/crawl-ref/source/macro.cc index 384483ef09..6b87824d35 100644 --- a/crawl-ref/source/macro.cc +++ b/crawl-ref/source/macro.cc @@ -1036,11 +1036,12 @@ static void _read_macros_from(const char* filename) } else if (s.length() >= 3 && s[0] == 'K' && s[2] == ':') { - keymc = KeymapContext(KMC_DEFAULT + s[1] - '0'); - if (keymc >= KMC_DEFAULT && keymc < KMC_CONTEXT_COUNT) + const KeymapContext ctx = KeymapContext(KMC_DEFAULT + s[1] - '0'); + if (ctx >= KMC_DEFAULT && ctx < KMC_CONTEXT_COUNT) { key = parse_keyseq(s.substr(3)); keymap = true; + keymc = ctx; } } else if (s.substr(0, 2) == "M:") |