Index: common/include/str.h
===================================================================
--- common/include/str.h	(revision fb759795c1d61e3bc6f51e162a581c6f01e42172)
+++ common/include/str.h	(revision a65ccc4edc568b2dbbf3459bac7554a58b88f36f)
@@ -149,4 +149,6 @@
 extern char *str_tok(char *, const char *, char **);
 
+extern size_t str_sanitize(char *, size_t, uint8_t);
+
 extern errno_t str_uint8_t(const char *, const char **, unsigned int, bool,
     uint8_t *);
@@ -165,6 +167,4 @@
 extern void bin_order_suffix(const uint64_t, uint64_t *, const char **, bool);
 
-extern size_t str_sanitize(char *str, size_t n, uint8_t replacement);
-
 /*
  * TODO: Get rid of this.
Index: common/str.c
===================================================================
--- common/str.c	(revision fb759795c1d61e3bc6f51e162a581c6f01e42172)
+++ common/str.c	(revision a65ccc4edc568b2dbbf3459bac7554a58b88f36f)
@@ -547,4 +547,11 @@
 
 	for (; n > 0 && b[0]; b++, n--) {
+		if (b[0] < ' ') {
+			/* C0 control codes */
+			b[0] = replacement;
+			count++;
+			continue;
+		}
+
 		int cont = _continuation_bytes(b[0]);
 		if (__builtin_expect(cont, 0) == 0)
@@ -584,4 +591,11 @@
 		}
 
+		bool c1_control = (b[0] == 0b11000010 && b[1] < 0b10100000);
+		if (cont == 1 && c1_control) {
+			b[0] = replacement;
+			count++;
+			continue;
+		}
+
 		/* 0b1110!!!! 0b10!xxxxx 0b10xxxxxx */
 		if (cont == 2 && !(b[0] & 0b00001111) && !(b[1] & 0b00100000)) {
@@ -619,4 +633,8 @@
 }
 
+/** Replaces any byte that's not part of a complete valid UTF-8 character
+ * encoding with a replacement byte.
+ * Also replaces C0 and C1 control codes.
+ */
 size_t str_sanitize(char *str, size_t n, uint8_t replacement)
 {
Index: kernel/generic/src/console/console.c
===================================================================
--- kernel/generic/src/console/console.c	(revision fb759795c1d61e3bc6f51e162a581c6f01e42172)
+++ kernel/generic/src/console/console.c	(revision a65ccc4edc568b2dbbf3459bac7554a58b88f36f)
@@ -384,4 +384,7 @@
 		data[size] = 0;
 
+		uint8_t substitute = '\x1a';
+		str_sanitize(data, size, substitute);
+
 		switch (cmd) {
 		case KIO_WRITE:
