From: Rayhan Faizel Date: Tue, 17 Sep 2024 17:58:45 +0000 (+0530) Subject: libxl_conf: Fix config generation for multiple serial devices X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=cb2a6ef8b570895cd6ec7d63cd61b49681b9474f;p=libvirt.git libxl_conf: Fix config generation for multiple serial devices Currently, an array of libxl_string_list (char **) or in other words, a triple char pointer is initialized. This is dereferenced to a char ** type and stored in serial_list, which is NULL at this point. There is an attempt to reference an element of this serial_list when making a call to libxlMakeChrdevStr which causes a segmentation fault. To fix this, we simply allocate an array of char * instead of libxl_string_list. This patch also adds testcases to extend coverage over both single serial and multiple serial cases. Signed-off-by: Rayhan Faizel Reviewed-by: Martin Kletzander --- diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index 62e1be6672..8c91489ffd 100644 --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -692,7 +692,7 @@ libxlMakeDomBuildInfo(virDomainDef *def, 0) return -1; } else { - b_info->u.hvm.serial_list = *g_new0(libxl_string_list, def->nserials + 1); + b_info->u.hvm.serial_list = g_new0(char *, def->nserials + 1); for (i = 0; i < def->nserials; i++) { if (libxlMakeChrdevStr(def->serials[i], &b_info->u.hvm.serial_list[i]) < 0) diff --git a/tests/libxlxml2domconfigdata/multiple-serial.json b/tests/libxlxml2domconfigdata/multiple-serial.json new file mode 100644 index 0000000000..121f2d1260 --- /dev/null +++ b/tests/libxlxml2domconfigdata/multiple-serial.json @@ -0,0 +1,63 @@ +{ + "c_info": { + "type": "hvm", + "name": "test-hvm", + "uuid": "2147d599-9cc6-c0dc-92ab-4064b5446e9b" + }, + "b_info": { + "max_vcpus": 4, + "avail_vcpus": [ + 0, + 1, + 2, + 3 + ], + "max_memkb": 1048576, + "target_memkb": 1048576, + "shadow_memkb": 1234, + "sched_params": { + + }, + "acpi": "True", + "apic": "True", + "type.hvm": { + "pae": "True", + "nographic": "True", + "vga": { + "kind": "none" + }, + "vnc": { + "enable": "False" + }, + "sdl": { + "enable": "False" + }, + "spice": { + + }, + "serial_list": [ + "null", + "stdio", + "vc", + "pty", + "pipe:/tmp/file", + "file:/tmp/serial.log", + "/dev/ttyS2", + "udp::9999@:0", + "tcp:127.0.0.1:9999", + "unix:/tmp/serial-server.sock,server,nowait" + ], + "boot": "c", + "rdm": { + + } + }, + "arch_arm": { + + }, + "arch_x86": { + + } + }, + "on_reboot": "restart" +} diff --git a/tests/libxlxml2domconfigdata/multiple-serial.xml b/tests/libxlxml2domconfigdata/multiple-serial.xml new file mode 100644 index 0000000000..c50ffd0bb4 --- /dev/null +++ b/tests/libxlxml2domconfigdata/multiple-serial.xml @@ -0,0 +1,47 @@ + + test-hvm + None + 2147d599-9cc6-c0dc-92ab-4064b5446e9b + 1048576 + 1048576 + 4 + destroy + restart + destroy + + + hvm + /usr/lib/xen/boot/hvmloader + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/libxlxml2domconfigdata/single-serial.json b/tests/libxlxml2domconfigdata/single-serial.json new file mode 100644 index 0000000000..a736e6f805 --- /dev/null +++ b/tests/libxlxml2domconfigdata/single-serial.json @@ -0,0 +1,52 @@ +{ + "c_info": { + "type": "hvm", + "name": "test-hvm", + "uuid": "2147d599-9cc6-c0dc-92ab-4064b5446e9b" + }, + "b_info": { + "max_vcpus": 4, + "avail_vcpus": [ + 0, + 1, + 2, + 3 + ], + "max_memkb": 1048576, + "target_memkb": 1048576, + "shadow_memkb": 1234, + "sched_params": { + + }, + "acpi": "True", + "apic": "True", + "type.hvm": { + "pae": "True", + "nographic": "True", + "vga": { + "kind": "none" + }, + "vnc": { + "enable": "False" + }, + "sdl": { + "enable": "False" + }, + "spice": { + + }, + "serial": "pty", + "boot": "c", + "rdm": { + + } + }, + "arch_arm": { + + }, + "arch_x86": { + + } + }, + "on_reboot": "restart" +} diff --git a/tests/libxlxml2domconfigdata/single-serial.xml b/tests/libxlxml2domconfigdata/single-serial.xml new file mode 100644 index 0000000000..f468024189 --- /dev/null +++ b/tests/libxlxml2domconfigdata/single-serial.xml @@ -0,0 +1,25 @@ + + test-hvm + None + 2147d599-9cc6-c0dc-92ab-4064b5446e9b + 1048576 + 1048576 + 4 + destroy + restart + destroy + + + hvm + /usr/lib/xen/boot/hvmloader + + + + + + + + + + + diff --git a/tests/libxlxml2domconfigtest.c b/tests/libxlxml2domconfigtest.c index 21c4e7d149..255855b156 100644 --- a/tests/libxlxml2domconfigtest.c +++ b/tests/libxlxml2domconfigtest.c @@ -208,6 +208,9 @@ mymain(void) DO_TEST("max-eventchannels-hvm"); + DO_TEST("single-serial"); + DO_TEST("multiple-serial"); + unlink("libxl-driver.log"); testXLFreeDriver(driver);