2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-29 13:38:26 +00:00

Ensure that named_server_t is properly initialized

There was a ubsan error reporting an invalid value for interface_auto
(a boolean value cannot be 190) because it was not initialized. To
avoid this problem happening again, ensure the whole of the server
structure is initialized to zero before setting the (relatively few)
non-zero elements.
This commit is contained in:
Tony Finch 2022-09-09 08:21:10 +01:00
parent 37cdd6b51d
commit 7b71b1020f
2 changed files with 12 additions and 66 deletions

View File

@ -1,3 +1,6 @@
5963. [bug] Ensure struct named_server is properly initialized.
[GL #6531]
5962. [placeholder]
5961. [placeholder]

View File

@ -10236,13 +10236,14 @@ named_server_create(isc_mem_t *mctx, named_server_t **serverp) {
isc_result_t result;
named_server_t *server = isc_mem_get(mctx, sizeof(*server));
if (server == NULL) {
fatal(server, "allocating server object", ISC_R_NOMEMORY);
}
server->mctx = mctx;
server->task = NULL;
server->zonemgr = NULL;
*server = (named_server_t){
.mctx = mctx,
.statsfile = isc_mem_strdup(mctx, "named.stats"),
.bindkeysfile = isc_mem_strdup(mctx, named_g_defaultbindkeys),
.dumpfile = isc_mem_strdup(mctx, "named_dump.db"),
.secrootsfile = isc_mem_strdup(mctx, "named.secroots"),
.recfile = isc_mem_strdup(mctx, "named.recursing"),
};
#ifdef USE_DNSRPS
CHECKFATAL(dns_dnsrps_server_create(), "initializing RPZ service "
@ -10250,10 +10251,8 @@ named_server_create(isc_mem_t *mctx, named_server_t **serverp) {
#endif /* ifdef USE_DNSRPS */
/* Initialize server data structures. */
server->interfacemgr = NULL;
ISC_LIST_INIT(server->kasplist);
ISC_LIST_INIT(server->viewlist);
server->in_roothints = NULL;
/* Must be first. */
CHECKFATAL(dst_lib_init(named_g_mctx, named_g_engine), "initializing "
@ -10275,7 +10274,6 @@ named_server_create(isc_mem_t *mctx, named_server_t **serverp) {
isc_task_setname(server->task, "server", server);
isc_taskmgr_setexcltask(named_g_taskmgr, server->task);
server->sctx = NULL;
CHECKFATAL(ns_server_create(mctx, get_matching_view, &server->sctx),
"creating server context");
@ -10302,50 +10300,11 @@ named_server_create(isc_mem_t *mctx, named_server_t **serverp) {
server->sighup = isc_signal_new(
named_g_loopmgr, named_server_reloadwanted, server, SIGHUP);
server->interface_timer = NULL;
server->heartbeat_timer = NULL;
server->pps_timer = NULL;
server->tat_timer = NULL;
server->interface_interval = 0;
server->heartbeat_interval = 0;
CHECKFATAL(dns_zonemgr_create(named_g_mctx, named_g_loopmgr,
named_g_taskmgr, named_g_netmgr,
&server->zonemgr),
"dns_zonemgr_create");
server->statsfile = isc_mem_strdup(server->mctx, "named.stats");
CHECKFATAL(server->statsfile == NULL ? ISC_R_NOMEMORY : ISC_R_SUCCESS,
"isc_mem_strdup");
server->bindkeysfile = isc_mem_strdup(server->mctx,
named_g_defaultbindkeys);
CHECKFATAL(server->bindkeysfile == NULL ? ISC_R_NOMEMORY
: ISC_R_SUCCESS,
"isc_mem_strdup");
server->dumpfile = isc_mem_strdup(server->mctx, "named_dump.db");
CHECKFATAL(server->dumpfile == NULL ? ISC_R_NOMEMORY : ISC_R_SUCCESS,
"isc_mem_strdup");
server->secrootsfile = isc_mem_strdup(server->mctx, "named.secroots");
CHECKFATAL(server->secrootsfile == NULL ? ISC_R_NOMEMORY
: ISC_R_SUCCESS,
"isc_mem_strdup");
server->recfile = isc_mem_strdup(server->mctx, "named.recursing");
CHECKFATAL(server->recfile == NULL ? ISC_R_NOMEMORY : ISC_R_SUCCESS,
"isc_mem_strdup");
server->hostname_set = false;
server->hostname = NULL;
server->version_set = false;
server->version = NULL;
server->zonestats = NULL;
server->resolverstats = NULL;
server->sockstats = NULL;
CHECKFATAL(isc_stats_create(server->mctx, &server->sockstats,
isc_sockstatscounter_max),
"isc_stats_create");
@ -10359,33 +10318,17 @@ named_server_create(isc_mem_t *mctx, named_server_t **serverp) {
dns_resstatscounter_max),
"dns_stats_create (resolver)");
server->flushonshutdown = false;
server->controls = NULL;
CHECKFATAL(named_controls_create(server, &server->controls),
"named_controls_create");
server->dispatchgen = 0;
ISC_LIST_INIT(server->dispatches);
ISC_LIST_INIT(server->statschannels);
ISC_LIST_INIT(server->cachelist);
server->sessionkey = NULL;
server->session_keyfile = NULL;
server->session_keyname = NULL;
server->session_keyalg = DST_ALG_UNKNOWN;
server->session_keybits = 0;
server->lockfile = NULL;
server->dtenv = NULL;
server->magic = NAMED_SERVER_MAGIC;
server->tlsctx_server_cache = NULL;
server->tlsctx_client_cache = NULL;
*serverp = server;
}