# HG changeset patch # User John "Elwin" Edwards # Date 1505091862 14400 # Node ID 4573b355cdc11cc87004d48703b96b18204c3206 # Parent aa0eefcd7df6ce9489c965a1ef5ef326bc313974 UltraRogue: prevent bad array accesses in call(). Marking non-magic items caused segfaults because item_color was set to NULL. item_type could also be used as an out-of-bounds index. These problems have been fixed by only using these variables when the mark argument is false, in which case they are properly initialized. A fall-through case statement was also fixed. diff -r aa0eefcd7df6 -r 4573b355cdc1 urogue/command.c --- a/urogue/command.c Sat Sep 09 07:25:23 2017 -0400 +++ b/urogue/command.c Sun Sep 10 21:04:22 2017 -0400 @@ -1303,6 +1303,7 @@ case STICK: item_type = TYP_STICK; item_color = ws_made; + break; default: if (!mark) { @@ -1312,10 +1313,7 @@ break; } - elsewise = (guess_items[item_type][obj->o_which] != NULL ? - guess_items[item_type][obj->o_which] : item_color[obj->o_which]); - - if (know_items[item_type][obj->o_which] && !mark) + if (!mark && know_items[item_type][obj->o_which]) { msg("That has already been identified."); return; @@ -1331,6 +1329,9 @@ } else { + elsewise = (guess_items[item_type][obj->o_which] != NULL ? + guess_items[item_type][obj->o_which] : item_color[obj->o_which]); + msg("Was called \"%s\".", elsewise); msg("What do you want to call it? ");