On Mon, Aug 19, 2024 at 12:49:19 +0200, Peter Krempa wrote:
On Mon, Aug 19, 2024 at 12:00:56 +0200, Anthony Harivel wrote:
> Hi,
>
> I'm trying to implement the libvirt part of a new feature that has
> landed in QEMU staging [1].
> The current draft of this implementations is the following [2].
> It compiles on top of master.
> But when I want to run the tests suites, I hit an issue I don't managed
> to find the problem.
>
> It runs until:
> [...]
> 278/279 libvirt:bin / qemuxmlconftest FAIL 8.63s exit status 1
> [...]
>
> then it tells me to run the following to understand the issue:
> VIR_TEST_DEBUG=1 VIR_TEST_RANGE=850-851,854-855
/home/aharivel/work/libvirt/build/tests/qemuxmlconftest
>
> It outputs this:
> [...]
> 850) QEMU XML def -> XML kvm-features.x86_64-latest ...
> In
'/home/aharivel/work/libvirt/tests/qemuxmlconfdata/kvm-features.x86_64-latest.xml':
> Offset 533
> Expect [ socket='/run/qemu-vmsr-helper.sock'/]
> Actual [/]
These test cases parse an XML and format it back.
You've got a bug in the code formatting the socket into the XML:
if (def->kvm_features->socket == NULL) {
virBufferAsprintf(&childBuf, "
socket='%s'/>\n",
def->kvm_features->socket);
Also note that for user-provided strings you must use
virBufferEscapeString in order to properly escape XML entities within
strings.
virBufferEscapeString will avoid formatting the whole format string
completely when the string argument is NULL.
Thus if you just skip the '/>\n' part
} else {
virBufferAddLit(&childBuf, "/>\n");
and do this unconditionally you can avoid the condition altogether.
}