mirror of
https://github.com/caddyserver/caddy.git
synced 2025-05-25 12:20:34 +08:00
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
This commit is contained in:

committed by
Matt Holt

parent
a19da07b72
commit
93bc1b72e3
16
admin.go
16
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
|
||||
|
Reference in New Issue
Block a user