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 <rayhan.faizel@gmail.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
This commit is contained in:
Rayhan Faizel 2024-09-17 23:28:45 +05:30 committed by Martin Kletzander
parent 655225315c
commit cb2a6ef8b5
6 changed files with 191 additions and 1 deletions

View File

@ -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)

View File

@ -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"
}

View File

@ -0,0 +1,47 @@
<domain type='xen'>
<name>test-hvm</name>
<description>None</description>
<uuid>2147d599-9cc6-c0dc-92ab-4064b5446e9b</uuid>
<memory>1048576</memory>
<currentMemory>1048576</currentMemory>
<vcpu>4</vcpu>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<clock offset='utc'/>
<os>
<type>hvm</type>
<loader>/usr/lib/xen/boot/hvmloader</loader>
<boot dev='hd'/>
</os>
<features>
<apic/>
<acpi/>
<pae/>
</features>
<devices>
<serial type='null'/>
<serial type='stdio'/>
<serial type='vc'/>
<serial type='pty'/>
<serial type='pipe'>
<source path='/tmp/file'/>
</serial>
<serial type='file'>
<source path='/tmp/serial.log'/>
</serial>
<serial type='dev'>
<source path='/dev/ttyS2'/>
</serial>
<serial type='udp'>
<source mode='connect' service='9999'/>
</serial>
<serial type='tcp'>
<source mode='connect' host='127.0.0.1' service='9999'/>
<protocol type='raw'/>
</serial>
<serial type='unix'>
<source mode='bind' path='/tmp/serial-server.sock'/>
</serial>
</devices>
</domain>

View File

@ -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"
}

View File

@ -0,0 +1,25 @@
<domain type='xen'>
<name>test-hvm</name>
<description>None</description>
<uuid>2147d599-9cc6-c0dc-92ab-4064b5446e9b</uuid>
<memory>1048576</memory>
<currentMemory>1048576</currentMemory>
<vcpu>4</vcpu>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<clock offset='utc'/>
<os>
<type>hvm</type>
<loader>/usr/lib/xen/boot/hvmloader</loader>
<boot dev='hd'/>
</os>
<features>
<apic/>
<acpi/>
<pae/>
</features>
<devices>
<serial type='pty'/>
</devices>
</domain>

View File

@ -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);