[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [xen master] golang/xenlight: fix StringList toC conversion
commit 1422d8db1b3dfdf7d9179944e594876e5e356a4b Author: Nick Rosbrook <rosbrookn@xxxxxxxxx> AuthorDate: Mon May 24 16:36:43 2021 -0400 Commit: George Dunlap <george.dunlap@xxxxxxxxxx> CommitDate: Mon Jun 21 16:49:08 2021 +0100 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@xxxxxxxxxxxx> Reviewed-by: George Dunlap <george.dunlap@xxxxxxxxxx> --- tools/golang/xenlight/xenlight.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go index b9189dec5c..13171d0ad1 100644 --- a/tools/golang/xenlight/xenlight.go +++ b/tools/golang/xenlight/xenlight.go @@ -491,13 +491,14 @@ func (sl *StringList) fromC(csl *C.libxl_string_list) error { func (sl StringList) toC(csl *C.libxl_string_list) error { var char *C.char - size := len(sl) + size := len(sl) + 1 *csl = (C.libxl_string_list)(C.malloc(C.ulong(size) * C.ulong(unsafe.Sizeof(char)))) - clist := (*[1 << 30]*C.char)(unsafe.Pointer(csl))[:size:size] + clist := (*[1 << 30]*C.char)(unsafe.Pointer(*csl))[:size:size] for i, v := range sl { clist[i] = C.CString(v) } + clist[len(clist)-1] = nil return nil } -- generated by git-patchbot for /home/xen/git/xen.git#master
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |