Skip to content
Snippets Groups Projects
Commit ffe071a1 authored by Daniel Salzman's avatar Daniel Salzman Committed by Jan Včelák
Browse files

sockaddr: add explicit string termination after gethostname()

parent 52b21ae2
Branches
Tags
No related merge requests found
......@@ -186,10 +186,12 @@ void sockaddr_port_set(struct sockaddr_storage *ss, uint16_t port)
char *sockaddr_hostname(void)
{
/* Fetch hostname. */
char host[KNOT_DNAME_MAXLEN] = {'\0'};
if (gethostname(host, KNOT_DNAME_MAXLEN) != 0) {
char host[KNOT_DNAME_MAXLEN + 1] = { '\0' };
if (gethostname(host, sizeof(host)) != 0) {
return NULL;
}
/* Just to be sure. */
host[sizeof(host) - 1] = '\0';
/* Fetch canonical name for this address/DNS. */
struct addrinfo hints, *info = NULL;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment