From d94a6a5e17277521cfd32c725dbae33b3bd6bd07 Mon Sep 17 00:00:00 2001 From: CPunch Date: Fri, 15 Apr 2022 15:40:25 -0500 Subject: [PATCH] shellT_addChar(): Added ascii validation, ignore non-printable input --- shell/src/sterm.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/shell/src/sterm.c b/shell/src/sterm.c index b4d93b7..611a9e8 100644 --- a/shell/src/sterm.c +++ b/shell/src/sterm.c @@ -153,6 +153,10 @@ void shellT_setPrompt(char *_prompt) { prompt = _prompt; } +bool isAscii(int c) { + return c >= ' ' && c <= '~'; /* covers every non-controller related ascii characters (ignoring the extended character range) */ +} + void shellT_addChar(tShell_client *client, int c) { int i; @@ -189,6 +193,10 @@ void shellT_addChar(tShell_client *client, int c) { break; case KEY_UP: case KEY_DOWN: break; /* ignore these */ default: + /* we only want to accept valid input, just ignore non-ascii characters */ + if (!isAscii(c)) + return; + laikaM_growarray(char, cmd, 1, cmdCount, cmdCap); laikaM_insertarray(cmd, cmdCount, cmdCursor, 1); cmd[cmdCursor++] = c;