Currently, we put no strains on escape sequence possibly leaving users
with console that cannot be terminated. However, not all ASCII
characters can be used as escape sequence. Only those falling in
@ - _ can be; implement and document this constraint.
# include <errno.h>
# include <unistd.h>
# include <signal.h>
+# include <c-ctype.h>
# include "internal.h"
# include "console.h"
vshGetEscapeChar(const char *s)
{
if (*s == '^')
- return CONTROL(s[1]);
+ return CONTROL(c_toupper(s[1]));
return *s;
}
vshPrint(ctl, "\n");
}
+static bool
+vshAllowedEscapeChar(char c)
+{
+ /* Allowed escape characters:
+ * a-z A-Z @ [ \ ] ^ _
+ */
+ return ('a' <= c && c <= 'z') ||
+ ('@' <= c && c <= '_');
+}
+
/*
* argv[]: virsh [options] [command]
*
case 'e':
len = strlen(optarg);
- if ((len == 2 && *optarg == '^') ||
+ if ((len == 2 && *optarg == '^' &&
+ vshAllowedEscapeChar(optarg[1])) ||
(len == 1 && *optarg != '^')) {
ctl->escapeChar = optarg;
} else {
=item B<-e>, B<--escape> I<string>
Set alternative escape sequence for I<console> command. By default,
-telnet's B<^]> is used.
+telnet's B<^]> is used. Allowed characters when using hat notation are:
+alphabetic character, @, [, ], \, ^, _.
=back