summaryrefslogtreecommitdiff
path: root/admin.go
diff options
context:
space:
mode:
authorMohammed Al Sahaf <msaa1990@gmail.com>2019-11-12 01:33:38 +0300
committerMatt Holt <mholt@users.noreply.github.com>2019-11-11 15:33:38 -0700
commit93bc1b72e3cd566e6447ad7a1f832474aad5dfcc (patch)
tree05ddeb324261d7058925948baa0077752fd5e453 /admin.go
parenta19da07b72d84432341990bcedce511fe2f980da (diff)
core: Use port ranges to avoid OOM with bad inputs (#2859)
* fix OOM issue caught by fuzzing * use ParsedAddress as the struct name for the result of ParseNetworkAddress * simplify code using the ParsedAddress type * minor cleanups
Diffstat (limited to 'admin.go')
-rw-r--r--admin.go16
1 files changed, 6 insertions, 10 deletions
diff --git a/admin.go b/admin.go
index 502a968..b1ced18 100644
--- a/admin.go
+++ b/admin.go
@@ -48,23 +48,19 @@ type AdminConfig struct {
// listenAddr extracts a singular listen address from ac.Listen,
// returning the network and the address of the listener.
-func (admin AdminConfig) listenAddr() (netw string, addr string, err error) {
- var listenAddrs []string
+func (admin AdminConfig) listenAddr() (string, string, error) {
input := admin.Listen
if input == "" {
input = DefaultAdminListen
}
- netw, listenAddrs, err = ParseNetworkAddress(input)
+ listenAddr, err := ParseNetworkAddress(input)
if err != nil {
- err = fmt.Errorf("parsing admin listener address: %v", err)
- return
+ return "", "", fmt.Errorf("parsing admin listener address: %v", err)
}
- if len(listenAddrs) != 1 {
- err = fmt.Errorf("admin endpoint must have exactly one address; cannot listen on %v", listenAddrs)
- return
+ if listenAddr.PortRangeSize() != 1 {
+ return "", "", fmt.Errorf("admin endpoint must have exactly one address; cannot listen on %v", listenAddr)
}
- addr = listenAddrs[0]
- return
+ return listenAddr.Network, listenAddr.JoinHostPort(0), nil
}
// newAdminHandler reads admin's config and returns an http.Handler suitable