From 89971a5fc97b0ecf688e30b42ee794b80ac873a1 Mon Sep 17 00:00:00 2001 From: Ingo Paschke Date: Tue, 12 May 2026 15:31:44 +0200 Subject: [PATCH] Amiga: fix extended-command menu mouse-pick The amii_get_ext_cmd menu used the first character of each command as the item identity (id.a_char) and then linearly searched extcmdlist for the first command starting with that character. Many commands share a first letter, so picking #airlevel returned #adjust, #wipe returned #wear, etc. Store the actual index in id.a_int and read it back directly. While in that function, size obufp at BUFSZ (was 100) and replace the unbounded strcpy from extcmdlist[i].ef_txt with strncpy + explicit NUL. --- sys/amiga/winami.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/sys/amiga/winami.c b/sys/amiga/winami.c index 6fdd95b55..631af1771 100644 --- a/sys/amiga/winami.c +++ b/sys/amiga/winami.c @@ -375,7 +375,7 @@ amii_get_ext_cmd(void) int bottom = 0; struct Window *w; - char obufp[100]; + char obufp[BUFSZ]; char *bufp = obufp; int c; int com_index, oindex; @@ -417,7 +417,7 @@ amii_get_ext_cmd(void) amii_start_menu(win, MENU_BEHAVE_STANDARD); for (i = 0; extcmdlist[i].ef_txt != NULL; ++i) { - id.a_char = extcmdlist[i].ef_txt[0]; + id.a_int = i; sprintf(buf, "%-10s - %s ", extcmdlist[i].ef_txt, extcmdlist[i].ef_desc); amii_add_menu(win, (const glyph_info *) 0, &id, @@ -432,16 +432,14 @@ amii_get_ext_cmd(void) if (sel == 0) { return (-1); } else { - sel = mip->item.a_char; - for (i = 0; extcmdlist[i].ef_txt != NULL; ++i) { - if (sel == extcmdlist[i].ef_txt[0]) - break; - } + i = mip->item.a_int; /* copy in the text */ if (extcmdlist[i].ef_txt != NULL) { amii_clear_nhwindow(WIN_MESSAGE); - strcpy(bufp = obufp, extcmdlist[i].ef_txt); + strncpy(obufp, extcmdlist[i].ef_txt, sizeof(obufp) - 1); + obufp[sizeof(obufp) - 1] = '\0'; + bufp = obufp; (void) put_ext_cmd(obufp, colx, cw, bottom); return (i); } else