Browse code

Fix panic while merging log configs to nil map

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
(cherry picked from commit 7dff31064824ed1f9b046fe5c29bd707e663ee0b)
Signed-off-by: Tibor Vass <tibor@docker.com>

Brian Goff authored on 2016/07/13 04:05:44
Showing 2 changed files
... ...
@@ -150,6 +150,10 @@ func (daemon *Daemon) mergeAndVerifyLogConfig(cfg *containertypes.LogConfig) err
150 150
 		cfg.Type = daemon.defaultLogConfig.Type
151 151
 	}
152 152
 
153
+	if cfg.Config == nil {
154
+		cfg.Config = make(map[string]string)
155
+	}
156
+
153 157
 	if cfg.Type == daemon.defaultLogConfig.Type {
154 158
 		for k, v := range daemon.defaultLogConfig.Config {
155 159
 			if _, ok := cfg.Config[k]; !ok {
156 160
new file mode 100644
... ...
@@ -0,0 +1,15 @@
0
+package daemon
1
+
2
+import (
3
+	"testing"
4
+
5
+	containertypes "github.com/docker/engine-api/types/container"
6
+)
7
+
8
+func TestMergeAndVerifyLogConfigNilConfig(t *testing.T) {
9
+	d := &Daemon{defaultLogConfig: containertypes.LogConfig{Type: "json-file", Config: map[string]string{"max-file": "1"}}}
10
+	cfg := containertypes.LogConfig{Type: d.defaultLogConfig.Type}
11
+	if err := d.mergeAndVerifyLogConfig(&cfg); err != nil {
12
+		t.Fatal(err)
13
+	}
14
+}