mirror of
https://github.com/berlin-open-wireless-lab/DAWN.git
synced 2025-03-09 15:40:12 +00:00
uci: truncate hostname at first dot
Oh, and stop at the size of the target buffer too.
This commit is contained in:
parent
77619e9b18
commit
bd35961de8
1 changed files with 8 additions and 1 deletions
|
@ -34,7 +34,14 @@ void uci_get_hostname(char* hostname)
|
||||||
|
|
||||||
if(ptr.flags & UCI_LOOKUP_COMPLETE)
|
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);
|
uci_free_context(c);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue