mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-11-14 18:32:55 +00:00
Update regex to disallow leading zeros
Also updated a comment to point to a non-experimental RFC. Signed-off-by: jbzdarkid <jbzdarkid@gmail.com>
This commit is contained in:
parent
89c80947df
commit
8090071eff
2 changed files with 13 additions and 3 deletions
|
@ -1018,9 +1018,11 @@ valid_ip() {
|
|||
local stat=1
|
||||
|
||||
# Regex matching one IPv4 component, i.e. an integer from 0 to 255.
|
||||
local ipv4elem="(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[0-9]{1,2})";
|
||||
# Regex matching an optional port beginning with # matching optional port number starting '#' with range of 1 to 65536
|
||||
local portelem="(:(6553[0-5]|655[0-2][0-9]|65[0-4][0-9]{2}|6[0-4][0-9]{3}|[1-5][0-9]{4}|[0-9]{1,4}))?";
|
||||
# See https://tools.ietf.org/html/rfc1340
|
||||
local ipv4elem="(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]?|0)";
|
||||
# Regex matching an optional port beginning with : from 0 to 65535
|
||||
# See https://tools.ietf.org/html/rfc1340#page-33
|
||||
local portelem="(:(6553[0-5]|655[0-2][0-9]|65[0-4][0-9]{2}|6[0-4][0-9]{3}|[1-5][0-9]{4}|[1-9][0-9]{0,3}|0))?";
|
||||
# Build a full IPv4 regex from the above subexpressions
|
||||
local regex="^${ipv4elem}\.${ipv4elem}\.${ipv4elem}\.${ipv4elem}${portelem}$"
|
||||
|
||||
|
|
|
@ -555,6 +555,14 @@ def test_validate_ip(Pihole):
|
|||
test_address('8.8.8.8:65535')
|
||||
test_address('8.8.8.8:65536', False)
|
||||
test_address('8.8.8.8:-1', False)
|
||||
test_address('00.0.0.0', False)
|
||||
test_address('010.0.0.0', False)
|
||||
test_address('001.0.0.0', False)
|
||||
test_address('0.0.0.0:00', False)
|
||||
test_address('0.0.0.0:01', False)
|
||||
test_address('0.0.0.0:001', False)
|
||||
test_address('0.0.0.0:0001', False)
|
||||
test_address('0.0.0.0:00001', False)
|
||||
|
||||
|
||||
def test_os_check_fails(Pihole):
|
||||
|
|
Loading…
Reference in a new issue