瀏覽代碼

Fix panic while merging log configs to nil map

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
Brian Goff 9 年之前
父節點
當前提交
7dff310648
共有 2 個文件被更改,包括 19 次插入0 次删除
  1. 4 0
      daemon/logs.go
  2. 15 0
      daemon/logs_test.go

+ 4 - 0
daemon/logs.go

@@ -150,6 +150,10 @@ func (daemon *Daemon) mergeAndVerifyLogConfig(cfg *containertypes.LogConfig) err
 		cfg.Type = daemon.defaultLogConfig.Type
 	}
 
+	if cfg.Config == nil {
+		cfg.Config = make(map[string]string)
+	}
+
 	if cfg.Type == daemon.defaultLogConfig.Type {
 		for k, v := range daemon.defaultLogConfig.Config {
 			if _, ok := cfg.Config[k]; !ok {

+ 15 - 0
daemon/logs_test.go

@@ -0,0 +1,15 @@
+package daemon
+
+import (
+	"testing"
+
+	containertypes "github.com/docker/engine-api/types/container"
+)
+
+func TestMergeAndVerifyLogConfigNilConfig(t *testing.T) {
+	d := &Daemon{defaultLogConfig: containertypes.LogConfig{Type: "json-file", Config: map[string]string{"max-file": "1"}}}
+	cfg := containertypes.LogConfig{Type: d.defaultLogConfig.Type}
+	if err := d.mergeAndVerifyLogConfig(&cfg); err != nil {
+		t.Fatal(err)
+	}
+}