summaryrefslogtreecommitdiff
path: root/lib/asn.c
diff options
context:
space:
mode:
authoranlan_cs <vic.lan@pica8.com>2023-02-22 20:57:07 +0800
committeranlan_cs <vic.lan@pica8.com>2023-02-24 21:13:19 +0800
commitb7d890dd4567bb1e45fd42cac81e6fbee43e4a9d (patch)
tree2e01bbbe63d460fe68abcb6dfd57ae023a42846e /lib/asn.c
parentee0aaff4bc2f57cdfd250d5f84a3893983246ff5 (diff)
lib: some ASNUMs should be forbidden
In current code, some ASNUMs with redundant zero are legal, e.g. "1.01", "01.1", "1.001", "001.1", and more. They should be forbidden. Signed-off-by: anlan_cs <vic.lan@pica8.com>
Diffstat (limited to 'lib/asn.c')
-rw-r--r--lib/asn.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/asn.c b/lib/asn.c
index c64666375d..4042f5846c 100644
--- a/lib/asn.c
+++ b/lib/asn.c
@@ -52,6 +52,10 @@ static bool asn_str2asn_internal(const char *asstring, as_t *asn,
if (!isdigit((unsigned char)*p))
goto end;
+ /* leading zero is forbidden */
+ if (*p == '0' && isdigit((unsigned char)*(p + 1)))
+ goto end;
+
temp_val = 0;
while (isdigit((unsigned char)*p)) {
digit = (*p) - '0';
@@ -65,11 +69,17 @@ static bool asn_str2asn_internal(const char *asstring, as_t *asn,
high = (uint32_t)temp_val;
if (*p == '.') { /* dot format */
p++;
- temp_val = 0;
+
if (*p == '\0' && partial) {
*partial = true;
goto end;
}
+
+ /* leading zero is forbidden */
+ if (*p == '0' && isdigit((unsigned char)*(p + 1)))
+ goto end;
+
+ temp_val = 0;
while (isdigit((unsigned char)*p)) {
digit = (*p) - '0';
temp_val *= 10;