From: Guido Günther Date: Thu, 13 Oct 2011 21:48:40 +0000 (+0200) Subject: virBufferEscapeShell: Emit quotes for the empty string X-Git-Tag: v0.9.7-rc1~80 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=04323fbcb4dd4bbd480aaa68ff0e8f1f5bfca7d4;p=thirdparty%2Flibvirt.git virBufferEscapeShell: Emit quotes for the empty string Make the empty string return '' to match cmdEcho's behavior. --- diff --git a/src/util/buf.c b/src/util/buf.c index f582cd2227..b7fcf6d603 100644 --- a/src/util/buf.c +++ b/src/util/buf.c @@ -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; }