From 50a0053bd869b72313cc96ab73108bb83079c3f5 Mon Sep 17 00:00:00 2001 From: Olivier Poitrey Date: Fri, 2 Apr 2021 20:13:51 +0200 Subject: [PATCH] Fix 08 parsed as decimal while 018 rejected. --- lib/netmask.coffee | 6 +++--- test/badnets.coffee | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/netmask.coffee b/lib/netmask.coffee index c2c345a..1e77497 100644 --- a/lib/netmask.coffee +++ b/lib/netmask.coffee @@ -57,14 +57,14 @@ atob = (s) -> i = 0 if s.length > 1 and s[i] == '0' if s[i+1] == 'x' or s[i+1] == 'X' - i+=2 + i += 2 base = 16 - else if '0' <= s[i+1] and s[i+1] <= '7' + else if '0' <= s[i+1] and s[i+1] <= '9' i++ base = 8 dmax = '7' start = i - while s.length > 0 + while i < s.length if '0' <= s[i] and s[i] <= dmax n = (n*base + (chr(s[i])-chr0)) >>> 0 else if base == 16 diff --git a/test/badnets.coffee b/test/badnets.coffee index 271fba1..5ab8096 100644 --- a/test/badnets.coffee +++ b/test/badnets.coffee @@ -42,6 +42,7 @@ vows.describe('Invalid IP format') '1.2.3.4 ': shouldFailWithError 'Invalid net' '1 .2.3.4': shouldFailWithError 'Invalid net' '018.0.0.0': shouldFailWithError 'Invalid net' + '08.0.0.0': shouldFailWithError 'Invalid net' '0xfg.0.0.0': shouldFailWithError 'Invalid net' .export(module)