golang/xenlight: fix StringList toC conversion
authorNick Rosbrook <rosbrookn@gmail.com>
Mon, 24 May 2021 20:36:43 +0000 (16:36 -0400)
committerGeorge Dunlap <george.dunlap@citrix.com>
Mon, 21 Jun 2021 15:49:08 +0000 (16:49 +0100)
commit1422d8db1b3dfdf7d9179944e594876e5e356a4b
treec16b2f8fe3268b2d0631b5978db36c547bdcbb2b
parentb291ce703b9cebef0800267446334e867588354a
golang/xenlight: fix StringList toC conversion

The current implementation of StringList.toC does not correctly account
for how libxl_string_list is expected to be laid out in C, which is clear
when one looks at libxl_string_list_length in libxl.c. In particular,
StringList.toC does not account for the extra memory that should be
allocated for the "sentinel" entry. And, when using the "slice trick" to
create a slice that can address C memory, the unsafe.Pointer conversion
should be on a C.libxl_string_list, not *C.libxl_string_list.

Fix these problems by (1) allocating an extra slot in the slice used to
address the C memory, and explicity set the last entry to nil so the C
memory will be zeroed out, and (2) dereferencing csl in the
unsafe.Pointer conversion.

Signed-off-by: Nick Rosbrook <rosbrookn@ainfosec.com>
Reviewed-by: George Dunlap <george.dunlap@citrix.com>
tools/golang/xenlight/xenlight.go