mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-25 01:34:11 +03:00
virBufferEscapeShell: Emit quotes for the empty string
Make the empty string return '' to match cmdEcho's behavior.
This commit is contained in:
parent
dad15a2e02
commit
04323fbcb4
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user