mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
devicemapper: fix zero-sized field access
Fixes: #15279
Due to
7904946eeb
the devices field is dropped.
This solution works on go1.4 and go1.5
Signed-off-by: Vincent Batts <vbatts@redhat.com>
This commit is contained in:
parent
b9094633f3
commit
f83d05c3be
2 changed files with 24 additions and 8 deletions
|
@ -1509,12 +1509,16 @@ func (devices *DeviceSet) deactivatePool() error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if d, err := devicemapper.GetDeps(devname); err == nil {
|
||||
// Access to more Debug output
|
||||
logrus.Debugf("[devmapper] devicemapper.GetDeps() %s: %#v", devname, d)
|
||||
|
||||
if devinfo.Exists == 0 {
|
||||
return nil
|
||||
}
|
||||
if devinfo.Exists != 0 {
|
||||
return devicemapper.RemoveDevice(devname)
|
||||
if err := devicemapper.RemoveDevice(devname); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if d, err := devicemapper.GetDeps(devname); err == nil {
|
||||
logrus.Warnf("[devmapper] device %s still has %d active dependents", devname, d.Count)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue