From 25b0312e8cc9bd064f8f3124b73adfd00f4033bf Mon Sep 17 00:00:00 2001 From: Vincent Batts Date: Fri, 7 Aug 2015 10:18:20 -0400 Subject: [PATCH] devicemapper: fix zero-sized field access Fixes: #15279 Due to https://github.com/golang/go/commit/7904946eeb35faece61bbf6f5b3cc8be2f519c17 the devices field is dropped. This solution works on go1.4 and go1.5 Signed-off-by: Vincent Batts --- devicemapper/devmapper_wrapper.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/devicemapper/devmapper_wrapper.go b/devicemapper/devmapper_wrapper.go index 87c2003..44ca772 100644 --- a/devicemapper/devmapper_wrapper.go +++ b/devicemapper/devmapper_wrapper.go @@ -38,7 +38,10 @@ static void log_with_errno_init() */ import "C" -import "unsafe" +import ( + "reflect" + "unsafe" +) type ( CDmTask C.struct_dm_task @@ -184,12 +187,21 @@ func dmTaskGetDepsFct(task *CDmTask) *Deps { if Cdeps == nil { return nil } + + // golang issue: https://github.com/golang/go/issues/11925 + hdr := reflect.SliceHeader{ + Data: uintptr(unsafe.Pointer(uintptr(unsafe.Pointer(Cdeps)) + unsafe.Sizeof(*Cdeps))), + Len: int(Cdeps.count), + Cap: int(Cdeps.count), + } + devices := *(*[]C.uint64_t)(unsafe.Pointer(&hdr)) + deps := &Deps{ Count: uint32(Cdeps.count), Filler: uint32(Cdeps.filler), } - for _, device := range Cdeps.device { - deps.Device = append(deps.Device, (uint64)(device)) + for _, device := range devices { + deps.Device = append(deps.Device, uint64(device)) } return deps }