Browse code

Fix possible segfault in config reload

This commit fixes two possible crashes in the `*Daemon` bound method
`reloadMaxConcurrentDownloadsAndUploads()`.

The first fixed issue is when `daemon.imageService` is `nil`. The second
panic can occur if the provided `*config.Config` is incomplete and the
fields `conf.MaxConcurrentDownloads` or `conf.MaxConcurrentUploads` are
`nil`.

Signed-off-by: Sascha Grunert <sgrunert@suse.com>

Sascha Grunert authored on 2019/01/10 23:34:02
Showing 1 changed files
... ...
@@ -84,25 +84,26 @@ func (daemon *Daemon) reloadDebug(conf *config.Config, attributes map[string]str
84 84
 func (daemon *Daemon) reloadMaxConcurrentDownloadsAndUploads(conf *config.Config, attributes map[string]string) {
85 85
 	// If no value is set for max-concurrent-downloads we assume it is the default value
86 86
 	// We always "reset" as the cost is lightweight and easy to maintain.
87
+	maxConcurrentDownloads := config.DefaultMaxConcurrentDownloads
87 88
 	if conf.IsValueSet("max-concurrent-downloads") && conf.MaxConcurrentDownloads != nil {
88
-		*daemon.configStore.MaxConcurrentDownloads = *conf.MaxConcurrentDownloads
89
-	} else {
90
-		maxConcurrentDownloads := config.DefaultMaxConcurrentDownloads
91
-		daemon.configStore.MaxConcurrentDownloads = &maxConcurrentDownloads
89
+		maxConcurrentDownloads = *conf.MaxConcurrentDownloads
92 90
 	}
91
+	daemon.configStore.MaxConcurrentDownloads = &maxConcurrentDownloads
93 92
 	logrus.Debugf("Reset Max Concurrent Downloads: %d", *daemon.configStore.MaxConcurrentDownloads)
94 93
 
95 94
 	// If no value is set for max-concurrent-upload we assume it is the default value
96 95
 	// We always "reset" as the cost is lightweight and easy to maintain.
96
+	maxConcurrentUploads := config.DefaultMaxConcurrentUploads
97 97
 	if conf.IsValueSet("max-concurrent-uploads") && conf.MaxConcurrentUploads != nil {
98
-		*daemon.configStore.MaxConcurrentUploads = *conf.MaxConcurrentUploads
99
-	} else {
100
-		maxConcurrentUploads := config.DefaultMaxConcurrentUploads
101
-		daemon.configStore.MaxConcurrentUploads = &maxConcurrentUploads
98
+		maxConcurrentUploads = *conf.MaxConcurrentUploads
102 99
 	}
100
+	daemon.configStore.MaxConcurrentUploads = &maxConcurrentUploads
103 101
 	logrus.Debugf("Reset Max Concurrent Uploads: %d", *daemon.configStore.MaxConcurrentUploads)
104 102
 
105
-	daemon.imageService.UpdateConfig(conf.MaxConcurrentDownloads, conf.MaxConcurrentUploads)
103
+	if daemon.imageService != nil {
104
+		daemon.imageService.UpdateConfig(&maxConcurrentDownloads, &maxConcurrentUploads)
105
+	}
106
+
106 107
 	// prepare reload event attributes with updatable configurations
107 108
 	attributes["max-concurrent-downloads"] = fmt.Sprintf("%d", *daemon.configStore.MaxConcurrentDownloads)
108 109
 	// prepare reload event attributes with updatable configurations