FTPD: make sure that the passive ip, if provided, is valid

The server will refuse to start if the provided passive ip is not a
valid IPv4 address.

Fixes #376
This commit is contained in:
Nicola Murino
2021-04-16 15:08:10 +02:00
parent 683ba6cd5b
commit 124c471a2b
5 changed files with 46 additions and 1 deletions

View File

@@ -387,6 +387,27 @@ func TestInitialization(t *testing.T) {
_, err = server.GetSettings()
assert.Error(t, err)
binding = Binding{
Port: 2121,
ForcePassiveIP: "192.168.1",
}
server = NewServer(c, configDir, binding, 0)
_, err = server.GetSettings()
if assert.Error(t, err) {
assert.Contains(t, err.Error(), "is not valid")
}
binding.ForcePassiveIP = "::ffff:192.168.89.9"
err = binding.checkPassiveIP()
assert.NoError(t, err)
assert.Equal(t, "192.168.89.9", binding.ForcePassiveIP)
binding.ForcePassiveIP = "::1"
err = binding.checkPassiveIP()
if assert.Error(t, err) {
assert.Contains(t, err.Error(), "is not a valid IPv4 address")
}
err = ReloadCertificateMgr()
assert.NoError(t, err)