Skip to content

Commit fff6657

Browse files
committed
- Fix that fast_reload does not terminate the server
on malloc failure for dnstap, or if gethostname fails. Thanks to Qifan Zhang, Palo Alto Networks, for the report.
1 parent 45d1e75 commit fff6657

4 files changed

Lines changed: 47 additions & 22 deletions

File tree

daemon/remote.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6673,9 +6673,12 @@ fr_reload_config(struct fast_reload_thread* fr, struct config_file* newcfg,
66736673
}
66746674
#ifdef USE_DNSTAP
66756675
if(env->cfg->dnstap) {
6676-
if(!fr->fr_nopause)
6677-
dt_apply_cfg(daemon->dtenv, env->cfg);
6678-
else dt_apply_logcfg(daemon->dtenv, env->cfg);
6676+
if(!fr->fr_nopause) {
6677+
if(!dt_apply_cfg(daemon->dtenv, env->cfg))
6678+
log_warn("fast_reload: dnstap identity/version metadata not updated due to allocation failure");
6679+
} else {
6680+
dt_apply_logcfg(daemon->dtenv, env->cfg);
6681+
}
66796682
}
66806683
#endif
66816684
fr_adjust_cache(env, ct->oldcfg);

dnstap/dnstap.c

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -176,63 +176,79 @@ dt_create(struct config_file* cfg)
176176
env->dtio = dt_io_thread_create();
177177
if(!env->dtio) {
178178
log_err("malloc failure");
179-
free(env);
179+
dt_delete(env);
180180
return NULL;
181181
}
182182
if(!dt_io_thread_apply_cfg(env->dtio, cfg)) {
183-
dt_io_thread_delete(env->dtio);
184-
free(env);
183+
dt_delete(env);
184+
return NULL;
185+
}
186+
if(!dt_apply_cfg(env, cfg)) {
187+
dt_delete(env);
185188
return NULL;
186189
}
187-
dt_apply_cfg(env, cfg);
188190
return env;
189191
}
190192

191-
static void
193+
static int
192194
dt_apply_identity(struct dt_env *env, struct config_file *cfg)
193195
{
194196
char buf[MAXHOSTNAMELEN+1];
195197
if (!cfg->dnstap_send_identity) {
196198
free(env->identity);
197199
env->identity = NULL;
198-
return;
200+
env->len_identity = 0;
201+
return 1;
199202
}
200203
free(env->identity);
201204
if (cfg->dnstap_identity == NULL || cfg->dnstap_identity[0] == 0) {
202205
if (gethostname(buf, MAXHOSTNAMELEN) == 0) {
203206
buf[MAXHOSTNAMELEN] = 0;
204207
env->identity = strdup(buf);
205208
} else {
206-
fatal_exit("dt_apply_identity: gethostname() failed");
209+
log_err("dt_apply_identity: gethostname() failed: %s",
210+
strerror(errno));
211+
env->identity = NULL;
212+
env->len_identity = 0;
213+
return 0;
207214
}
208215
} else {
209216
env->identity = strdup(cfg->dnstap_identity);
210217
}
211-
if (env->identity == NULL)
212-
fatal_exit("dt_apply_identity: strdup() failed");
218+
if (env->identity == NULL) {
219+
log_err("dt_apply_identity: strdup() failed");
220+
env->len_identity = 0;
221+
return 0;
222+
}
213223
env->len_identity = (unsigned int)strlen(env->identity);
214224
verbose(VERB_OPS, "dnstap identity field set to \"%s\"",
215225
env->identity);
226+
return 1;
216227
}
217228

218-
static void
229+
static int
219230
dt_apply_version(struct dt_env *env, struct config_file *cfg)
220231
{
221232
if (!cfg->dnstap_send_version) {
222233
free(env->version);
223234
env->version = NULL;
224-
return;
235+
env->len_version = 0;
236+
return 1;
225237
}
226238
free(env->version);
227239
if (cfg->dnstap_version == NULL || cfg->dnstap_version[0] == 0)
228240
env->version = strdup(PACKAGE_STRING);
229241
else
230242
env->version = strdup(cfg->dnstap_version);
231-
if (env->version == NULL)
232-
fatal_exit("dt_apply_version: strdup() failed");
243+
if (env->version == NULL) {
244+
log_err("dt_apply_version: strdup() failed");
245+
env->len_version = 0;
246+
return 0;
247+
}
233248
env->len_version = (unsigned int)strlen(env->version);
234249
verbose(VERB_OPS, "dnstap version field set to \"%s\"",
235250
env->version);
251+
return 1;
236252
}
237253

238254
void
@@ -276,15 +292,18 @@ dt_apply_logcfg(struct dt_env *env, struct config_file *cfg)
276292
lock_basic_unlock(&env->sample_lock);
277293
}
278294

279-
void
295+
int
280296
dt_apply_cfg(struct dt_env *env, struct config_file *cfg)
281297
{
282298
if (!cfg->dnstap)
283-
return;
299+
return 1;
284300

285-
dt_apply_identity(env, cfg);
286-
dt_apply_version(env, cfg);
287301
dt_apply_logcfg(env, cfg);
302+
if(!dt_apply_identity(env, cfg))
303+
return 0;
304+
if(!dt_apply_version(env, cfg))
305+
return 0;
306+
return 1;
288307
}
289308

290309
int

dnstap/dnstap.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ dt_create(struct config_file* cfg);
102102
* Apply config settings.
103103
* @param env: dnstap environment object.
104104
* @param cfg: new config settings.
105+
* @return false on failure.
105106
*/
106-
void
107-
dt_apply_cfg(struct dt_env *env, struct config_file *cfg);
107+
int dt_apply_cfg(struct dt_env *env, struct config_file *cfg);
108108

109109
/**
110110
* Apply config settings for log enable for message types.

doc/Changelog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@
4848
- Fix to check for malloc failure in rpz response create,
4949
for nodata and nxdomain, so it does not crash later.
5050
Thanks to Qifan Zhang, Palo Alto Networks, for the report.
51+
- Fix that fast_reload does not terminate the server
52+
on malloc failure for dnstap, or if gethostname fails.
53+
Thanks to Qifan Zhang, Palo Alto Networks, for the report.
5154

5255
16 June 2026: Wouter
5356
- Fix to disallow $INCLUDE for secondary zones. Start up

0 commit comments

Comments
 (0)