daemon/logger/fluentd: validate path element
fix some missing validation: the driver was silently ignoring path elements in some cases, and expecting a host (not an URL), and for unix sockets did not validate if a path was specified. For the latter case, we should have a fix in the upstream driver, as it uses an empty path as default path for the socket (`defaultSocketPath`), and performs no validation. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
b161616202
commit
0f40aefccd
2 changed files with 20 additions and 1 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue