Skip to content

Commit b58f157

Browse files
committed
listen_dnsport: check config variables to prevent SegFaults
1 parent ba65f50 commit b58f157

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

services/listen_dnsport.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2418,7 +2418,7 @@ static coap_context_t* coap_context_from_cfg(struct config_file *cfg)
24182418
char* oscore_conf = NULL;
24192419
char* oscore_seq_file = NULL;
24202420

2421-
if (cfg->coap_oscore_conf) {
2421+
if (cfg->coap_oscore_conf && cfg->coap_oscore_seq_file) {
24222422
oscore_conf = fname_after_chroot(cfg->coap_oscore_conf, cfg, 1);
24232423

24242424
if (!oscore_conf) {
@@ -2436,16 +2436,19 @@ static coap_context_t* coap_context_from_cfg(struct config_file *cfg)
24362436
}
24372437
}
24382438

2439-
coap_context = doc_setup_server_context(
2440-
(const uint8_t *)cfg->coaps_psk, strlen(cfg->coaps_psk), cfg->coaps_psk_id,
2441-
cfg->ssl_service_key, cfg->ssl_service_pem, NULL,
2442-
oscore_conf, oscore_seq_file);
2439+
if (cfg->coaps_psk && cfg->coaps_psk_id && cfg->ssl_service_key && cfg->ssl_service_pem) {
2440+
coap_context = doc_setup_server_context(
2441+
(const uint8_t *)cfg->coaps_psk, strlen(cfg->coaps_psk), cfg->coaps_psk_id,
2442+
cfg->ssl_service_key, cfg->ssl_service_pem, NULL,
2443+
oscore_conf, oscore_seq_file);
2444+
2445+
if (!coap_context) {
2446+
fatal_exit("Unable to create CoAP server context for DoC.");
2447+
}
2448+
}
24432449

24442450
free(oscore_conf);
24452451
free(oscore_seq_file);
2446-
if (!coap_context) {
2447-
fatal_exit("Unable to create CoAP server context for DoC.");
2448-
}
24492452

24502453
return coap_context;
24512454
}

0 commit comments

Comments
 (0)