Browse Source

uart_commands.c: sanitizing input even more

feature/2015
Christian Kroll 10 years ago
parent
commit
1e99121751
  1. 14
      src/uart/uart_commands.c

14
src/uart/uart_commands.c

@ -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) {

Loading…
Cancel
Save