comparison urogue/command.c @ 276:4573b355cdc1

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.
author John "Elwin" Edwards
date Sun, 10 Sep 2017 21:04:22 -0400
parents 88bd51f231e7
children e52a8a7ad4c5
comparison
equal deleted inserted replaced
275:aa0eefcd7df6 276:4573b355cdc1
1301 item_color = s_names; 1301 item_color = s_names;
1302 break; 1302 break;
1303 case STICK: 1303 case STICK:
1304 item_type = TYP_STICK; 1304 item_type = TYP_STICK;
1305 item_color = ws_made; 1305 item_color = ws_made;
1306 break;
1306 default: 1307 default:
1307 if (!mark) 1308 if (!mark)
1308 { 1309 {
1309 msg("You can't call that anything."); 1310 msg("You can't call that anything.");
1310 return; 1311 return;
1311 } 1312 }
1312 break; 1313 break;
1313 } 1314 }
1314 1315
1315 elsewise = (guess_items[item_type][obj->o_which] != NULL ? 1316 if (!mark && know_items[item_type][obj->o_which])
1316 guess_items[item_type][obj->o_which] : item_color[obj->o_which]);
1317
1318 if (know_items[item_type][obj->o_which] && !mark)
1319 { 1317 {
1320 msg("That has already been identified."); 1318 msg("That has already been identified.");
1321 return; 1319 return;
1322 } 1320 }
1323 1321
1329 msg("What do you want to mark it? "); 1327 msg("What do you want to mark it? ");
1330 prbuf[0] = '\0'; 1328 prbuf[0] = '\0';
1331 } 1329 }
1332 else 1330 else
1333 { 1331 {
1332 elsewise = (guess_items[item_type][obj->o_which] != NULL ?
1333 guess_items[item_type][obj->o_which] : item_color[obj->o_which]);
1334
1334 msg("Was called \"%s\".", elsewise); 1335 msg("Was called \"%s\".", elsewise);
1335 msg("What do you want to call it? "); 1336 msg("What do you want to call it? ");
1336 1337
1337 if (guess_items[item_type][obj->o_which] != NULL) 1338 if (guess_items[item_type][obj->o_which] != NULL)
1338 ur_free(guess_items[item_type][obj->o_which]); 1339 ur_free(guess_items[item_type][obj->o_which]);