uart_commands.c: sanitizing input even more

This commit is contained in:
Christian Kroll 2014-09-26 00:14:38 +02:00
parent ecec6bae36
commit 1e99121751
1 changed files with 8 additions and 6 deletions

View File

@ -277,7 +277,7 @@ static bool uartcmd_read_until_enter(void) {
break; break;
case '\b': // BS case '\b': // BS
case '\177': // DEL case '\177': // DEL
if ((g_rx_index != 0) && (g_rx_buffer[g_rx_index - 1] >= 32)) { if (g_rx_index != 0) {
g_rx_buffer[--g_rx_index] = 0; g_rx_buffer[--g_rx_index] = 0;
UART_PUTS_P(UART_STR_BACKSPACE); UART_PUTS_P(UART_STR_BACKSPACE);
} }
@ -285,12 +285,14 @@ static bool uartcmd_read_until_enter(void) {
case 27: // ignore Esc case 27: // ignore Esc
break; break;
default: default:
// only 7 bit ASCII can be processed // We don't accept control characters (except for \r and \n) and
if (uart_result > 0x7f) { // we also limit the input to 7 bit ASCII.
uart_result = '?'; if ((uart_result < 0x20) || (uart_result > 0x7f)) {
uart_putc('\007'); // complain via ASCII bell
} else {
g_rx_buffer[g_rx_index++] = uart_result; // accept input
uart_putc(uart_result); // echo input back to terminal
} }
g_rx_buffer[g_rx_index++] = uart_result;
uart_putc(uart_result);
break; break;
} }
} else if ((uart_result & 0xFF00u) != UART_NO_DATA) { } else if ((uart_result & 0xFF00u) != UART_NO_DATA) {