devicemapper: fix zero-sized field access
authorVincent Batts <vbatts@redhat.com>
Fri, 7 Aug 2015 14:18:20 +0000 (10:18 -0400)
committerTianon Gravi <tianon@debian.org>
Wed, 4 Nov 2015 08:09:02 +0000 (08:09 +0000)
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 <vbatts@redhat.com>
Gbp-Pq: Name 15404.patch

daemon/graphdriver/devmapper/deviceset.go
pkg/devicemapper/devmapper_wrapper.go

index 2eee33016783dad798ae3c1bf049fab9899a898b..a80736a393879f8c97098a904e14d6d53dc9af8a 100644 (file)
@@ -1482,12 +1482,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
index 87c200376f35ceedc5cf28887749b525e2e1660c..44ca772b9b2a703ba98fd03e51288dacd26f1dba 100644 (file)
@@ -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
 }