Skip to content

Commit

Permalink
core: Improved URN parsing according to RFC8141
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
anmartan committed Jul 5, 2024
1 parent dc7fc82 commit e73b321
Showing 1 changed file with 33 additions and 24 deletions.
57 changes: 33 additions & 24 deletions src/core/parser/parse_uri.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ int parse_uri(char *buf, int len, struct sip_uri *uri)
register char *p;
char *end;
char *pass;
char* f_component;
int found_user;
int error_headers;
uint32_t scheme;
Expand Down Expand Up @@ -237,28 +238,35 @@ 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 '#': \
uri->host.s = s; \
uri->host.len = p - s; \
f_component = p; \
break; \
case '&': \
case '@': \
goto error_bad_char


Expand Down Expand Up @@ -445,6 +453,7 @@ int parse_uri(char *buf, int len, struct sip_uri *uri)
end = buf + len;
p = buf + 4;
found_user = 0;
f_component = end;
error_headers = 0;
b = v = 0;
param = param_val = 0;
Expand Down Expand Up @@ -493,7 +502,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:
Expand Down Expand Up @@ -1107,7 +1116,7 @@ int parse_uri(char *buf, int len, struct sip_uri *uri)
case URI_HOST_P:
case URI_HOST6_END:
uri->host.s = s;
uri->host.len = p - s;
uri->host.len = f_component - s;
break;
case URI_HOST: /* error: null host */
case URI_HOST6_P: /* error: unterminated ipv6 reference*/
Expand Down

0 comments on commit e73b321

Please sign in to comment.