Browse code

api/server: better error checking to avoid unnecessary panics

Docker-DCO-1.1-Signed-off-by: Solomon Hykes <solomon@docker.com> (github: shykes)

Solomon Hykes authored on 2014/05/02 08:08:39
Showing 1 changed files
... ...
@@ -1267,6 +1267,9 @@ func ListenAndServe(proto, addr string, job *engine.Job) error {
1267 1267
 // ServeApi loops through all of the protocols sent in to docker and spawns
1268 1268
 // off a go routine to setup a serving http.Server for each.
1269 1269
 func ServeApi(job *engine.Job) engine.Status {
1270
+	if len(job.Args) == 0 {
1271
+		return job.Errorf("usage: %s PROTO://ADDR [PROTO://ADDR ...]", job.Name)
1272
+	}
1270 1273
 	var (
1271 1274
 		protoAddrs = job.Args
1272 1275
 		chErrors   = make(chan error, len(protoAddrs))
... ...
@@ -1279,6 +1282,9 @@ func ServeApi(job *engine.Job) engine.Status {
1279 1279
 
1280 1280
 	for _, protoAddr := range protoAddrs {
1281 1281
 		protoAddrParts := strings.SplitN(protoAddr, "://", 2)
1282
+		if len(protoAddrParts) != 2 {
1283
+			return job.Errorf("usage: %s PROTO://ADDR [PROTO://ADDR ...]", job.Name)
1284
+		}
1282 1285
 		go func() {
1283 1286
 			log.Printf("Listening for HTTP on %s (%s)\n", protoAddrParts[0], protoAddrParts[1])
1284 1287
 			chErrors <- ListenAndServe(protoAddrParts[0], protoAddrParts[1], job)