From 95dc93a2cedb17d671f5952538b3d39e12544107 Mon Sep 17 00:00:00 2001 From: anmartan Date: Thu, 4 Jul 2024 09:30:02 +0200 Subject: [PATCH] core: Improved URN parsing according to RFC8141 - Improved URN parsing to allow consuming URNs that contain 3 or more colons. Previosly URI parser treated some of the colons as separator between host and port causing the URN parsing to fail. --- src/core/parser/parse_uri.c | 48 +++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/src/core/parser/parse_uri.c b/src/core/parser/parse_uri.c index 9ccb62ee51e..4150c1598d6 100644 --- a/src/core/parser/parse_uri.c +++ b/src/core/parser/parse_uri.c @@ -237,28 +237,30 @@ int parse_uri(char *buf, int len, struct sip_uri *uri) } else \ goto error_bad_char -#define check_host_end \ - case ':': \ - /* found the host */ \ - uri->host.s = s; \ - uri->host.len = p - s; \ - state = URI_PORT; \ - s = p + 1; \ - break; \ - case ';': \ - uri->host.s = s; \ - uri->host.len = p - s; \ - state = URI_PARAM; \ - s = p + 1; \ - break; \ - case '?': \ - uri->host.s = s; \ - uri->host.len = p - s; \ - state = URI_HEADERS; \ - s = p + 1; \ - break; \ - case '&': \ - case '@': \ +#define check_host_end \ + case ':': \ + /* found the host */ \ + if(scheme != URN_SCH) { \ + uri->host.s = s; \ + uri->host.len = p - s; \ + state = URI_PORT; \ + s = p + 1; \ + } \ + break; \ + case ';': \ + uri->host.s = s; \ + uri->host.len = p - s; \ + state = URI_PARAM; \ + s = p + 1; \ + break; \ + case '?': \ + uri->host.s = s; \ + uri->host.len = p - s; \ + state = URI_HEADERS; \ + s = p + 1; \ + break; \ + case '&': \ + case '@': \ goto error_bad_char @@ -493,7 +495,7 @@ int parse_uri(char *buf, int len, struct sip_uri *uri) case '@': /* error no user part, or * be forgiving and accept it ? */ default: - state = URI_USER; + state = (scheme == URN_SCH) ? URI_HOST : URI_USER; } break; case URI_USER: