Merge pull request #15404 from vbatts/vbatts-dm-zero-sized-field
devicemapper: fix zero-sized field access
This commit is contained in:
commit
732af35366
1 changed files with 15 additions and 3 deletions
|
@ -38,7 +38,10 @@ static void log_with_errno_init()
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
import "unsafe"
|
import (
|
||||||
|
"reflect"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
CDmTask C.struct_dm_task
|
CDmTask C.struct_dm_task
|
||||||
|
@ -184,12 +187,21 @@ func dmTaskGetDepsFct(task *CDmTask) *Deps {
|
||||||
if Cdeps == nil {
|
if Cdeps == nil {
|
||||||
return 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{
|
deps := &Deps{
|
||||||
Count: uint32(Cdeps.count),
|
Count: uint32(Cdeps.count),
|
||||||
Filler: uint32(Cdeps.filler),
|
Filler: uint32(Cdeps.filler),
|
||||||
}
|
}
|
||||||
for _, device := range Cdeps.device {
|
for _, device := range devices {
|
||||||
deps.Device = append(deps.Device, (uint64)(device))
|
deps.Device = append(deps.Device, uint64(device))
|
||||||
}
|
}
|
||||||
return deps
|
return deps
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue