diff --git a/daemon/logger/fluentd/fluentd.go b/daemon/logger/fluentd/fluentd.go index 37f620c653..c2e6e0e171 100644 --- a/daemon/logger/fluentd/fluentd.go +++ b/daemon/logger/fluentd/fluentd.go @@ -277,6 +277,10 @@ func parseAddress(address string) (*location, error) { }, nil } + if !strings.Contains(address, "://") { + address = defaultProtocol + "://" + address + } + protocol := defaultProtocol if urlutil.IsTransportURL(address) { addr, err := url.Parse(address) @@ -285,6 +289,9 @@ func parseAddress(address string) (*location, error) { } // unix and unixgram socket if addr.Scheme == "unix" || addr.Scheme == "unixgram" { + if strings.TrimLeft(addr.Path, "/") == "" { + return nil, errors.New("path is empty") + } return &location{ protocol: addr.Scheme, host: "", @@ -295,6 +302,10 @@ func parseAddress(address string) (*location, error) { // tcp|udp protocol = addr.Scheme address = addr.Host + + if addr.Path != "" { + return nil, errors.New("should not contain a path element") + } } host, port, err := net.SplitHostPort(address) diff --git a/daemon/logger/fluentd/fluentd_test.go b/daemon/logger/fluentd/fluentd_test.go index b5a797b3e5..21db6f8509 100644 --- a/daemon/logger/fluentd/fluentd_test.go +++ b/daemon/logger/fluentd/fluentd_test.go @@ -102,7 +102,7 @@ func TestValidateLogOptAddress(t *testing.T) { }, { addr: "corrupted:c", - expectedErr: "invalid syntax", + expectedErr: "invalid port", }, { addr: "tcp://example.com:port", @@ -112,6 +112,10 @@ func TestValidateLogOptAddress(t *testing.T) { addr: "tcp://example.com:-1", expectedErr: "invalid port", }, + { + addr: "unix://", + expectedErr: "path is empty", + }, { addr: "unix:///some/socket.sock", expected: location{ @@ -136,6 +140,10 @@ func TestValidateLogOptAddress(t *testing.T) { address := tc.addr + path t.Run(address, func(t *testing.T) { err := ValidateLogOpt(map[string]string{addressKey: address}) + if path != "" { + assert.ErrorContains(t, err, "should not contain a path element") + return + } if tc.expectedErr != "" { assert.ErrorContains(t, err, tc.expectedErr) return