fix off by one: reserve space for 0-termination

This commit is contained in:
Christian Grothoff 2019-11-09 21:36:19 +01:00
parent c0a87f1087
commit 77b0e836d1
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC

View File

@ -265,25 +265,22 @@ TALER_url_join (const char *base_url,
unsigned int iparam = 0; unsigned int iparam = 0;
va_list args; va_list args;
struct TALER_Buffer buf = { 0 }; struct TALER_Buffer buf = { 0 };
size_t len = 0; size_t len;
GNUNET_assert (NULL != base_url); GNUNET_assert (NULL != base_url);
GNUNET_assert (NULL != path); GNUNET_assert (NULL != path);
if (0 == strlen (base_url))
if (strlen (base_url) == 0)
{ {
/* base URL can't be empty */ /* base URL can't be empty */
GNUNET_break (0); GNUNET_break (0);
return NULL; return NULL;
} }
if ('/' != base_url[strlen (base_url) - 1]) if ('/' != base_url[strlen (base_url) - 1])
{ {
/* Must be an actual base URL! */ /* Must be an actual base URL! */
GNUNET_break (0); GNUNET_break (0);
return NULL; return NULL;
} }
if ('/' == path[0]) if ('/' == path[0])
{ {
/* The path must be relative. */ /* The path must be relative. */
@ -291,14 +288,14 @@ TALER_url_join (const char *base_url,
return NULL; return NULL;
} }
// Path should be relative to existing path of base URL /* Path should be relative to existing path of base URL */
GNUNET_break ('/' != path[0]); GNUNET_break ('/' != path[0]);
if ('/' == path[0]) if ('/' == path[0])
GNUNET_break (0); GNUNET_break (0);
/* 1st pass: compute length */ /* 1st pass: compute length */
len += strlen (base_url) + strlen (path); len = strlen (base_url) + strlen (path) + 1;
va_start (args, path); va_start (args, path);
while (1) while (1)
@ -316,7 +313,6 @@ TALER_url_join (const char *base_url,
va_end (args); va_end (args);
TALER_buffer_prealloc (&buf, len); TALER_buffer_prealloc (&buf, len);
TALER_buffer_write_str (&buf, base_url); TALER_buffer_write_str (&buf, base_url);
TALER_buffer_write_str (&buf, path); TALER_buffer_write_str (&buf, path);
@ -325,6 +321,7 @@ TALER_url_join (const char *base_url,
{ {
char *key; char *key;
char *value; char *value;
key = va_arg (args, char *); key = va_arg (args, char *);
if (NULL == key) if (NULL == key)
break; break;