issue #1205 - crash using the curses interface

curses_yn_function() was returning a value that wasn't in the
subset of legal return values. This fixes that.

The unexpected return value of 32 (or space) then brought to
light an indexing error in the core that's been there a while,
apparently since at least 3.2.0, and that caused a null pointer
dereference in a strlen() call, which is what actually caused
the crash in issue #1205. This fixes that too.

Close #1205
This commit is contained in:
nhmall
2024-02-06 13:12:04 -05:00
parent 6c874267b8
commit 3a9e53a629
2 changed files with 3 additions and 2 deletions

View File

@@ -5232,7 +5232,7 @@ let_to_name(char let, boolean unpaid, boolean showsym)
else if ((pos = strchr(oth_symbols, let)) != 0)
class_name = oth_names[pos - oth_symbols];
else
class_name = names[0];
class_name = names[ILLOBJ_CLASS];
len = Strlen(class_name) + (unpaid ? sizeof "unpaid_" : sizeof "")
+ (oclass ? (Strlen(ocsymfmt) + invbuf_sympadding) : 0);

View File

@@ -323,7 +323,8 @@ curses_character_input_dialog(
}
break;
} else if ((answer == '\n') || (answer == '\r') || (answer == ' ')) {
if ((choices != NULL) && (def != '\0')) {
if ((choices != NULL)
&& ((def != '\0') || !strchr(choices, answer))) {
answer = def;
}
break;