diff --git a/sys/net/application_layer/gcoap/dns.c b/sys/net/application_layer/gcoap/dns.c index 1b0ce80d2c80..600acf4febf8 100644 --- a/sys/net/application_layer/gcoap/dns.c +++ b/sys/net/application_layer/gcoap/dns.c @@ -30,6 +30,7 @@ #include "net/sock/udp.h" #include "net/sock/util.h" #include "random.h" +#include "string_utils.h" #include "uri_parser.h" #include "ut_process.h" @@ -316,14 +317,10 @@ ssize_t gcoap_dns_server_proxy_get(char *proxy, size_t proxy_len) ssize_t res = 0; mutex_lock(&_client_mutex); if (_dns_server_uri_isset()) { - res = strlen(_uri); - if (((size_t)res + 1) > proxy_len) { - /* account for trailing \0 */ + res = strscpy(proxy, _proxy, proxy_len); + if (res == -E2BIG) { res = -ENOBUFS; } - else { - strcpy(proxy, _proxy); - } } mutex_unlock(&_client_mutex); return res;