From 8ca88d1f01f0e7d858c0c35107ecd6572da755c0 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Wed, 22 Aug 2018 06:51:20 +0200 Subject: [PATCH] net.ip.Address4: Reject malformed addresses --- source/tanya/net/ip.d | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/source/tanya/net/ip.d b/source/tanya/net/ip.d index 5c375ba..0785aaf 100644 --- a/source/tanya/net/ip.d +++ b/source/tanya/net/ip.d @@ -290,6 +290,10 @@ if (isInputRange!R && isSomeChar!(ElementType!R)) for (; shift != cond; shift += Address4.step, range.popFront()) { + if (range.empty || range.front == '.') + { + return typeof(return)(); + } result.address |= readIntegral!ubyte(range) << shift; if (range.empty || range.front != '.') { @@ -297,14 +301,23 @@ if (isInputRange!R && isSomeChar!(ElementType!R)) } } + if (range.empty || range.front == '.') + { + return typeof(return)(); + } result.address |= readIntegral!ubyte(range) << shift; return range.empty ? typeof(return)(result) : typeof(return)(); } -/// +// Rejects malformed addresses @nogc nothrow pure @safe unittest { assert(address4("256.0.0.1").isNothing); + assert(address4(".0.0.1").isNothing); + assert(address4("0..0.1").isNothing); + assert(address4("0.0.0.").isNothing); + assert(address4("0.0.").isNothing); + assert(address4("").isNothing); } /**