diff --git a/src/util/buf.c b/src/util/buf.c index 34347b5dd5..f582cd2227 100644 --- a/src/util/buf.c +++ b/src/util/buf.c @@ -524,13 +524,13 @@ virBufferEscapeShell(virBufferPtr buf, const char *str) *out++ = '\''; while (*cur != 0) { - *out++ = *cur++; if (*cur == '\'') { + *out++ = '\''; /* Replace literal ' with a close ', a \', and a open ' */ *out++ = '\\'; *out++ = '\''; - *out++ = '\''; } + *out++ = *cur++; } *out++ = '\''; *out = 0;