Skip to content

Commit 4c5082a

Browse files
committed
- Fix that fast_reload does not terminate the server if
random init for DNS cookies fails. The data is only random generated if cookies are enabled, and the random data is necessary. Thanks to Qifan Zhang, Palo Alto Networks, for the report.
1 parent 5fb892a commit 4c5082a

2 files changed

Lines changed: 31 additions & 8 deletions

File tree

doc/Changelog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@
5858
- Fix that fast_reload does not terminate the server
5959
on config read failure after malloc failure. Thanks to
6060
Qifan Zhang, Palo Alto Networks, for the report.
61+
- Fix that fast_reload does not terminate the server if
62+
random init for DNS cookies fails. The data is only random
63+
generated if cookies are enabled, and the random data
64+
is necessary. Thanks to Qifan Zhang, Palo Alto Networks,
65+
for the report.
6166

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

util/config_file.c

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ struct config_parser_state* cfg_parser = 0;
9494
static void init_outgoing_availports(int* array, int num);
9595

9696
/** init cookie with random data */
97-
static void init_cookie_secret(uint8_t* cookie_secret, size_t cookie_secret_len);
97+
static int init_cookie_secret(struct config_file* cfg);
9898

9999
struct config_file*
100100
config_create(void)
@@ -390,8 +390,7 @@ config_create(void)
390390
#endif
391391
cfg->do_answer_cookie = 0;
392392
memset(cfg->cookie_secret, 0, sizeof(cfg->cookie_secret));
393-
cfg->cookie_secret_len = 16;
394-
init_cookie_secret(cfg->cookie_secret, cfg->cookie_secret_len);
393+
cfg->cookie_secret_len = 0; /* not set yet */
395394
cfg->cookie_secret_file = NULL;
396395
#ifdef USE_CACHEDB
397396
if(!(cfg->cachedb_backend = strdup("testframe"))) goto error_exit;
@@ -1577,6 +1576,8 @@ config_read(struct config_file* cfg, const char* filename, const char* chroot)
15771576
}
15781577
globfree(&g);
15791578
config_auto_slab_values(cfg);
1579+
if(!init_cookie_secret(cfg))
1580+
return 0;
15801581
return 1;
15811582
}
15821583
#endif /* HAVE_GLOB */
@@ -1601,6 +1602,8 @@ config_read(struct config_file* cfg, const char* filename, const char* chroot)
16011602
}
16021603

16031604
config_auto_slab_values(cfg);
1605+
if(!init_cookie_secret(cfg))
1606+
return 0;
16041607
return 1;
16051608
}
16061609

@@ -1875,18 +1878,33 @@ config_delete(struct config_file* cfg)
18751878
free(cfg);
18761879
}
18771880

1878-
static void
1879-
init_cookie_secret(uint8_t* cookie_secret, size_t cookie_secret_len)
1881+
static int
1882+
init_cookie_secret(struct config_file* cfg)
18801883
{
1881-
struct ub_randstate *rand = ub_initstate(NULL);
1884+
struct ub_randstate* rand;
1885+
size_t cookie_secret_len;
1886+
uint8_t* cookie_secret;
1887+
if(!cfg->do_answer_cookie)
1888+
return 1;
1889+
if(cfg->cookie_secret_file && cfg->cookie_secret_file[0])
1890+
return 1;
1891+
if(cfg->cookie_secret_len != 0)
1892+
return 1;
18821893

1883-
if (!rand)
1884-
fatal_exit("could not init random generator");
1894+
rand = ub_initstate(NULL);
1895+
if(!rand) {
1896+
log_err("init_cookie_secret: could not init random generator");
1897+
return 0;
1898+
}
1899+
cfg->cookie_secret_len = 16;
1900+
cookie_secret_len = cfg->cookie_secret_len;
1901+
cookie_secret = cfg->cookie_secret;
18851902
while (cookie_secret_len) {
18861903
*cookie_secret++ = (uint8_t)ub_random(rand);
18871904
cookie_secret_len--;
18881905
}
18891906
ub_randfree(rand);
1907+
return 1;
18901908
}
18911909

18921910
static void

0 commit comments

Comments
 (0)