diff --git a/plugins/generic.c b/plugins/generic.c index d687a94e..2d83f339 100644 --- a/plugins/generic.c +++ b/plugins/generic.c @@ -86,11 +86,11 @@ static void skip_fmt(char *fmt, size_t len) * %h - hostname * %i - IP address */ -static int custom_server_url(ddns_info_t *info, ddns_alias_t *alias) +static int custom_server_url(char *buf, ddns_info_t *info, ddns_alias_t *alias) { char *ptr; - while ((ptr = strchr(info->server_url, '%'))) { + while ((ptr = strchr(buf, '%'))) { if (!strncmp(ptr, "%u", 2)) { if (strnlen(info->creds.username, USERNAME_LEN) <= 0) { logit(LOG_ERR, "Format specifier in ddns-path used: '%%u'," @@ -135,7 +135,7 @@ static int custom_server_url(ddns_info_t *info, ddns_alias_t *alias) return -1; } - return strlen(info->server_url); + return strlen(buf); } static char tohex(char code) @@ -204,17 +204,21 @@ static char *url_encode(char *str) */ static int request(ddns_t *ctx, ddns_info_t *info, ddns_alias_t *alias) { - int ret; - char *url; + char buf[2 * sizeof(info->server_url)]; char *arg = ""; + char *url; + int ret; + + /* Operate of copy of URL, may contain %-modifiers */ + strlcpy(buf, info->server_url, sizeof(buf)); /* - * if the user has specified modifiers, then he is probably - * aware of how to append his hostname or IP, otherwise just - * append the hostname or ip (depending on the append_myip option) + * if the user has specified modifiers, then they probably know + * how to append his hostname or IP, otherwise just append the + * hostname or ip (depending on the append_myip option) */ - if (strchr(info->server_url, '%')) { - if (custom_server_url(info, alias) <= 0) + if (strchr(buf, '%')) { + if (custom_server_url(buf, info, alias) <= 0) logit(LOG_ERR, "Invalid server URL: %s", info->server_url); } else { /* Backwards compat, default to append hostname */ @@ -224,7 +228,7 @@ static int request(ddns_t *ctx, ddns_info_t *info, ddns_alias_t *alias) arg = alias->address; } - url = url_encode(info->server_url); + url = url_encode(buf); if (!url) return 0;