From 75ca0e7919b3d7b02d2b832c93a0af2360129afc Mon Sep 17 00:00:00 2001 From: Georgia Garcia Date: Wed, 23 Aug 2023 10:49:53 -0300 Subject: [PATCH] parser: track leading zeros required for ipv6 range regex generator Signed-off-by: Georgia Garcia --- parser/bignum.h | 4 ++-- parser/parser_regex.c | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/parser/bignum.h b/parser/bignum.h index 438294457..757da4964 100644 --- a/parser/bignum.h +++ b/parser/bignum.h @@ -59,11 +59,11 @@ public: size_t i; bool flag = true; for (i = 0; i < 16; i++) { - if ((val[i] & 0xF0) >> 4 != 0) + if (flag && (val[i] & 0xF0) >> 4 != 0) flag = false; if (!flag) data.push_back((val[i] & 0xF0) >> 4); - if ((val[i] & 0x0F) != 0) + if (flag && (val[i] & 0x0F) != 0) flag = false; if (!flag) data.push_back(val[i] & 0x0F); diff --git a/parser/parser_regex.c b/parser/parser_regex.c index 440a1525e..7d1847692 100644 --- a/parser/parser_regex.c +++ b/parser/parser_regex.c @@ -886,7 +886,10 @@ static std::string generate_regex_range(bignum start, bignum end) for (auto &i: regex_range) { bignum sstart = i.first; bignum send = i.second; - + if (sstart.base == 16) { + for (j = (size_t) sstart.size(); j < 32; j++) + result << '0'; + } for (j = sstart.size() - 1; j >= 0; j--) { result << std::nouppercase; if (sstart[j] == send[j]) {