From 4dc13ab3dafd1e008325e6232085dfe0efc2f59f Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 2 Nov 2021 15:11:10 +0000 Subject: [PATCH] ConsoleReaderThread: strip control characters this fixes a bug I encountered when accidentally pressing ctrl+a+d (which inserts a chr(1) character), because it made the server unable to find the command - but still reported an error containing what looked like a valid command (character isn't printable). --- src/console/ConsoleReaderThread.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/console/ConsoleReaderThread.php b/src/console/ConsoleReaderThread.php index fde505f3c..dbf3770d3 100644 --- a/src/console/ConsoleReaderThread.php +++ b/src/console/ConsoleReaderThread.php @@ -114,7 +114,9 @@ final class ConsoleReaderThread extends Thread{ break; } - $buffer[] = preg_replace("#\\x1b\\x5b([^\\x1b]*\\x7e|[\\x40-\\x50])#", "", trim($command)); + $command = preg_replace("#\\x1b\\x5b([^\\x1b]*\\x7e|[\\x40-\\x50])#", "", trim($command)) ?? throw new AssumptionFailedError("This regex is assumed to be valid"); + $command = preg_replace('/[[:cntrl:]]/', '', $command) ?? throw new AssumptionFailedError("This regex is assumed to be valid"); + $buffer[] = $command; if($notifier !== null){ $notifier->wakeupSleeper(); }