hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit bb78b89134e922c9bd17292cd61cddb719117908
parent 656d84fd2c5ac764fbcfd0b2fd5132f85b528096
Author: Byron Torres <b@torresjrjr.com>
Date:   Fri, 27 Aug 2021 08:48:12 +0100

net::ip: invalidate leading zeros in IPv4 addrs

See #475  https://todo.sr.ht/~sircmpwn/hare/475

Signed-off-by: Byron Torres <b@torresjrjr.com>

Diffstat:
Mnet/ip/+test.ha | 1+
Mnet/ip/ip.ha | 3+++
2 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/net/ip/+test.ha b/net/ip/+test.ha @@ -29,6 +29,7 @@ fn ip_test(s: str, expected: (addr|invalid)) void = { ("192.168.18.1", [192, 168, 18, 1]: addr4), ("-127.0.0.1", invalid), ("127.-0.0.1", invalid), + ("0.011.001.000", invalid), ("::", [0...]: addr6), ("::1", [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1]: addr6), ("::FFFF:FFFF", [0,0,0,0,0,0,0,0,0,0,0,0,0xFF,0xFF,0xFF,0xFF]: addr6), diff --git a/net/ip/ip.ha b/net/ip/ip.ha @@ -58,6 +58,9 @@ fn parsev4(st: str) (addr4 | invalid) = { let i = 0z; for (i < 4; i += 1) { let s = wanttoken(&tok)?; + if (len(s) != 1 && strings::has_prefix(s, "0")) { + return invalid; + }; ret[i] = match (strconv::stou8(s)) { term: u8 => term, * => return invalid