uci: truncate hostname at first dot

Oh, and stop at the size of the target buffer too.
This commit is contained in:
David Woodhouse 2020-06-09 13:18:06 +01:00 committed by Polynomialdivision
parent 77619e9b18
commit bd35961de8

View file

@ -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);