1
0
mirror of https://github.com/CPunch/Laika.git synced 2024-11-25 05:50:15 +00:00

shellT_addChar(): Added ascii validation, ignore non-printable input

This commit is contained in:
CPunch 2022-04-15 15:40:25 -05:00
parent 9a6562f440
commit d94a6a5e17

View File

@ -153,6 +153,10 @@ void shellT_setPrompt(char *_prompt) {
prompt = _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) { void shellT_addChar(tShell_client *client, int c) {
int i; int i;
@ -189,6 +193,10 @@ void shellT_addChar(tShell_client *client, int c) {
break; break;
case KEY_UP: case KEY_DOWN: break; /* ignore these */ case KEY_UP: case KEY_DOWN: break; /* ignore these */
default: 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_growarray(char, cmd, 1, cmdCount, cmdCap);
laikaM_insertarray(cmd, cmdCount, cmdCursor, 1); laikaM_insertarray(cmd, cmdCount, cmdCursor, 1);
cmd[cmdCursor++] = c; cmd[cmdCursor++] = c;