]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virsh: Clarify escape sequence
authorMichal Privoznik <mprivozn@redhat.com>
Tue, 3 Apr 2012 12:59:06 +0000 (14:59 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 3 Apr 2012 15:03:53 +0000 (17:03 +0200)
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.

tools/console.c
tools/virsh.c
tools/virsh.pod

index ca226c3356fc958d89e3d300fad11019a12d6f33..34fde05eb707821058cffa3787d3ad45b1ca6488 100644 (file)
@@ -34,6 +34,7 @@
 # include <errno.h>
 # include <unistd.h>
 # include <signal.h>
+# include <c-ctype.h>
 
 # include "internal.h"
 # include "console.h"
@@ -292,7 +293,7 @@ static char
 vshGetEscapeChar(const char *s)
 {
     if (*s == '^')
-        return CONTROL(s[1]);
+        return CONTROL(c_toupper(s[1]));
 
     return *s;
 }
index 1ed2ddaae61235ed5d9d9dcf45d9f341fedc22fe..cfdd040b5e03e271e0f5cad981dc7eb13918d623 100644 (file)
@@ -19879,6 +19879,16 @@ vshShowVersion(vshControl *ctl ATTRIBUTE_UNUSED)
     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]
  *
@@ -19942,7 +19952,8 @@ vshParseArgv(vshControl *ctl, int argc, char **argv)
         case 'e':
             len = strlen(optarg);
 
-            if ((len == 2 && *optarg == '^') ||
+            if ((len == 2 && *optarg == '^' &&
+                 vshAllowedEscapeChar(optarg[1])) ||
                 (len == 1 && *optarg != '^')) {
                 ctl->escapeChar = optarg;
             } else {
index d4971a32cb48c86a7fb054a2d533079f3c157e91..a60e66770adace36ba532b92376c9046e6055d4c 100644 (file)
@@ -95,7 +95,8 @@ Output elapsed time information for each command.
 =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