]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
virBufferEscapeShell: Emit quotes for the empty string
authorGuido Günther <agx@sigxcpu.org>
Thu, 13 Oct 2011 21:48:40 +0000 (23:48 +0200)
committerGuido Günther <agx@sigxcpu.org>
Wed, 19 Oct 2011 07:24:01 +0000 (09:24 +0200)
Make the empty string return '' to match cmdEcho's behavior.

src/util/buf.c

index f582cd222749eaab7ec40cbfa39da010886e536e..b7fcf6d603ad8cea631eaa5c50df042c11c36444 100644 (file)
@@ -507,15 +507,20 @@ virBufferEscapeShell(virBufferPtr buf, const char *str)
         return;
 
     /* Only quote if str includes shell metacharacters. */
-    if (!strpbrk(str, "\r\t\n !\"#$&'()*;<>?[\\]^`{|}~")) {
+    if (*str && !strpbrk(str, "\r\t\n !\"#$&'()*;<>?[\\]^`{|}~")) {
         virBufferAdd(buf, str, -1);
         return;
     }
 
-    len = strlen(str);
-    if (xalloc_oversized(4, len) ||
-        VIR_ALLOC_N(escaped, 4 * len + 3) < 0) {
-        virBufferSetError(buf);
+    if (*str) {
+        len = strlen(str);
+        if (xalloc_oversized(4, len) ||
+            VIR_ALLOC_N(escaped, 4 * len + 3) < 0) {
+            virBufferSetError(buf);
+            return;
+        }
+    } else {
+        virBufferAdd(buf, "''", 2);
         return;
     }