From b7d890dd4567bb1e45fd42cac81e6fbee43e4a9d Mon Sep 17 00:00:00 2001 From: anlan_cs Date: Wed, 22 Feb 2023 20:57:07 +0800 Subject: [PATCH] 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 --- lib/asn.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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;