From bd35961de8f963b06913290356a6cd44a42a41fe Mon Sep 17 00:00:00 2001 From: David Woodhouse Date: Tue, 9 Jun 2020 13:18:06 +0100 Subject: [PATCH] uci: truncate hostname at first dot Oh, and stop at the size of the target buffer too. --- src/utils/dawn_uci.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/utils/dawn_uci.c b/src/utils/dawn_uci.c index ca2566d..8c4b7a3 100644 --- a/src/utils/dawn_uci.c +++ b/src/utils/dawn_uci.c @@ -34,7 +34,14 @@ void uci_get_hostname(char* hostname) if(ptr.flags & UCI_LOOKUP_COMPLETE) { - strncpy(hostname, ptr.o->v.string, HOST_NAME_MAX); + char *dot = strchr(ptr.o->v.string, '.'); + size_t len = HOST_NAME_MAX - 1; + + if (dot && dot < ptr.o->v.string + len) + { + len = dot - ptr.o->v.string; + } + snprintf(hostname, HOST_NAME_MAX, "%.*s", len, ptr.o->v.string); } uci_free_context(c);