From b7a6d14bdc56e9397be8c9bef9c3d991ff30fe77 Mon Sep 17 00:00:00 2001 From: Alexander Morozov Date: Mon, 17 Aug 2015 11:37:55 -0700 Subject: [PATCH] Do not allow corrupted syslog-address Signed-off-by: Alexander Morozov --- daemon/logger/syslog/syslog.go | 52 ++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/daemon/logger/syslog/syslog.go b/daemon/logger/syslog/syslog.go index a402e26193..eb44977547 100644 --- a/daemon/logger/syslog/syslog.go +++ b/daemon/logger/syslog/syslog.go @@ -107,33 +107,35 @@ func (s *syslogger) Name() string { } func parseAddress(address string) (string, string, error) { - if urlutil.IsTransportURL(address) { - url, err := url.Parse(address) - if err != nil { - return "", "", err - } - - // unix socket validation - if url.Scheme == "unix" { - if _, err := os.Stat(url.Path); err != nil { - return "", "", err - } - return url.Scheme, url.Path, nil - } - - // here we process tcp|udp - host := url.Host - if _, _, err := net.SplitHostPort(host); err != nil { - if !strings.Contains(err.Error(), "missing port in address") { - return "", "", err - } - host = host + ":514" - } - - return url.Scheme, host, nil + if address == "" { + return "", "", nil + } + if !urlutil.IsTransportURL(address) { + return "", "", fmt.Errorf("syslog-address should be in form proto://address, got %v", address) + } + url, err := url.Parse(address) + if err != nil { + return "", "", err } - return "", "", nil + // unix socket validation + if url.Scheme == "unix" { + if _, err := os.Stat(url.Path); err != nil { + return "", "", err + } + return url.Scheme, url.Path, nil + } + + // here we process tcp|udp + host := url.Host + if _, _, err := net.SplitHostPort(host); err != nil { + if !strings.Contains(err.Error(), "missing port in address") { + return "", "", err + } + host = host + ":514" + } + + return url.Scheme, host, nil } // ValidateLogOpt looks for syslog specific log options