Skip to content
Snippets Groups Projects
Unverified Commit b0309145 authored by Koen Zandberg's avatar Koen Zandberg
Browse files

sock_util: Limit URL scheme size

parent 4c183257
No related branches found
No related tags found
No related merge requests found
...@@ -53,8 +53,9 @@ int sock_udp_ep_fmt(const sock_udp_ep_t *endpoint, char *addr_str, uint16_t *por ...@@ -53,8 +53,9 @@ int sock_udp_ep_fmt(const sock_udp_ep_t *endpoint, char *addr_str, uint16_t *por
* "host.name:1234" and "/url/path". * "host.name:1234" and "/url/path".
* *
* @note Caller has to make sure hostport and urlpath can hold the results! * @note Caller has to make sure hostport and urlpath can hold the results!
* Make sure to provide space for SOCK_HOSTPORT_MAXLEN respectively * Make sure to provide space for @ref SOCK_HOSTPORT_MAXLEN respectively
* SOCK_URLPATH_MAXLEN bytes. * @ref SOCK_URLPATH_MAXLEN bytes.
* Scheme part of the URL is limited to @ref SOCK_SCHEME_MAXLEN length.
* *
* @param[in] url URL to split * @param[in] url URL to split
* @param[out] hostport where to write host:port * @param[out] hostport where to write host:port
...@@ -98,6 +99,9 @@ bool sock_udp_ep_equal(const sock_udp_ep_t *a, const sock_udp_ep_t *b); ...@@ -98,6 +99,9 @@ bool sock_udp_ep_equal(const sock_udp_ep_t *a, const sock_udp_ep_t *b);
* @name helper definitions * @name helper definitions
* @{ * @{
*/ */
#define SOCK_SCHEME_MAXLEN (16U) /**< maximum length of the scheme part
for sock_urlsplit. Ensures a hard
limit on the string iterator */
#define SOCK_HOSTPORT_MAXLEN (64U) /**< maximum length of host:port part for #define SOCK_HOSTPORT_MAXLEN (64U) /**< maximum length of host:port part for
sock_urlsplit() */ sock_urlsplit() */
#define SOCK_URLPATH_MAXLEN (64U) /**< maximum length path for #define SOCK_URLPATH_MAXLEN (64U) /**< maximum length path for
......
...@@ -85,8 +85,13 @@ int sock_udp_ep_fmt(const sock_udp_ep_t *endpoint, char *addr_str, uint16_t *por ...@@ -85,8 +85,13 @@ int sock_udp_ep_fmt(const sock_udp_ep_t *endpoint, char *addr_str, uint16_t *por
static char* _find_hoststart(const char *url) static char* _find_hoststart(const char *url)
{ {
/* Increment SOCK_SCHEME_MAXLEN due to comparison with the colon after the
* scheme part
*/
size_t remaining = SOCK_SCHEME_MAXLEN + 1;
char *urlpos = (char*)url; char *urlpos = (char*)url;
while(*urlpos) { while(*urlpos && remaining) {
remaining--;
if (*urlpos++ == ':') { if (*urlpos++ == ':') {
if (strncmp(urlpos, "//", 2) == 0) { if (strncmp(urlpos, "//", 2) == 0) {
return urlpos + 2; return urlpos + 2;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment