Commit 722338e9 authored by Daniel Salzman's avatar Daniel Salzman

knot: fix crash if sockaddr_hostname returns NULL (OpenWRT)

parent 6c981d00
......@@ -101,6 +101,10 @@ void conf_refresh_hostname(
free(conf->hostname);
conf->hostname = sockaddr_hostname();
if (conf->hostname == NULL) {
// Empty hostname fallback, NULL cannot be passed to strlen!
conf->hostname = strdup("");
}
}
static void init_cache(
......@@ -206,7 +210,7 @@ int conf_new(
// Cache the current hostname.
if (!(flags & CONF_FNOHOSTNAME)) {
out->hostname = sockaddr_hostname();
conf_refresh_hostname(out);
}
// Initialize cached values.
......
......@@ -241,7 +241,7 @@ int dnstap_load(struct query_plan *plan, struct query_module *self,
} else {
ctx->identity = sockaddr_hostname();
}
ctx->identity_len = strlen(ctx->identity);
ctx->identity_len = (ctx->identity != NULL) ? strlen(ctx->identity) : 0;
// Set version.
val = conf_mod_get(self->config, MOD_VERSION, self->id);
......
Markdown is supported
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