RADIUS server: Abort startup on allocation failures

Be more consistent on checking all parameter allocation and copying
steps within radius_server_init() and abort startup if anything fails
instead of trying to continue with other parts of the configuration.

Signed-off-by: Jouni Malinen <j@w1.fi>
This commit is contained in:
Jouni Malinen 2019-08-20 02:57:58 +03:00
parent fa1f0751cc
commit 9ce3bfaf47

View file

@ -2213,33 +2213,40 @@ radius_server_init(struct radius_server_conf *conf)
data->get_eap_user = conf->get_eap_user; data->get_eap_user = conf->get_eap_user;
if (conf->eap_req_id_text) { if (conf->eap_req_id_text) {
data->eap_req_id_text = os_malloc(conf->eap_req_id_text_len); data->eap_req_id_text = os_malloc(conf->eap_req_id_text_len);
if (data->eap_req_id_text) { if (!data->eap_req_id_text)
goto fail;
os_memcpy(data->eap_req_id_text, conf->eap_req_id_text, os_memcpy(data->eap_req_id_text, conf->eap_req_id_text,
conf->eap_req_id_text_len); conf->eap_req_id_text_len);
data->eap_req_id_text_len = conf->eap_req_id_text_len; data->eap_req_id_text_len = conf->eap_req_id_text_len;
} }
}
data->erp_domain = conf->erp_domain; data->erp_domain = conf->erp_domain;
if (conf->subscr_remediation_url) { if (conf->subscr_remediation_url) {
data->subscr_remediation_url = data->subscr_remediation_url =
os_strdup(conf->subscr_remediation_url); os_strdup(conf->subscr_remediation_url);
if (!data->subscr_remediation_url)
goto fail;
} }
data->subscr_remediation_method = conf->subscr_remediation_method; data->subscr_remediation_method = conf->subscr_remediation_method;
if (conf->hs20_sim_provisioning_url) if (conf->hs20_sim_provisioning_url) {
data->hs20_sim_provisioning_url = data->hs20_sim_provisioning_url =
os_strdup(conf->hs20_sim_provisioning_url); os_strdup(conf->hs20_sim_provisioning_url);
if (!data->hs20_sim_provisioning_url)
goto fail;
}
if (conf->t_c_server_url) if (conf->t_c_server_url) {
data->t_c_server_url = os_strdup(conf->t_c_server_url); data->t_c_server_url = os_strdup(conf->t_c_server_url);
if (!data->t_c_server_url)
goto fail;
}
#ifdef CONFIG_SQLITE #ifdef CONFIG_SQLITE
if (conf->sqlite_file) { if (conf->sqlite_file) {
if (sqlite3_open(conf->sqlite_file, &data->db)) { if (sqlite3_open(conf->sqlite_file, &data->db)) {
RADIUS_ERROR("Could not open SQLite file '%s'", RADIUS_ERROR("Could not open SQLite file '%s'",
conf->sqlite_file); conf->sqlite_file);
radius_server_deinit(data); goto fail;
return NULL;
} }
} }
#endif /* CONFIG_SQLITE */ #endif /* CONFIG_SQLITE */
@ -2253,8 +2260,7 @@ radius_server_init(struct radius_server_conf *conf)
conf->ipv6); conf->ipv6);
if (data->clients == NULL) { if (data->clients == NULL) {
wpa_printf(MSG_ERROR, "No RADIUS clients configured"); wpa_printf(MSG_ERROR, "No RADIUS clients configured");
radius_server_deinit(data); goto fail;
return NULL;
} }
#ifdef CONFIG_IPV6 #ifdef CONFIG_IPV6
@ -2265,14 +2271,12 @@ radius_server_init(struct radius_server_conf *conf)
data->auth_sock = radius_server_open_socket(conf->auth_port); data->auth_sock = radius_server_open_socket(conf->auth_port);
if (data->auth_sock < 0) { if (data->auth_sock < 0) {
wpa_printf(MSG_ERROR, "Failed to open UDP socket for RADIUS authentication server"); wpa_printf(MSG_ERROR, "Failed to open UDP socket for RADIUS authentication server");
radius_server_deinit(data); goto fail;
return NULL;
} }
if (eloop_register_read_sock(data->auth_sock, if (eloop_register_read_sock(data->auth_sock,
radius_server_receive_auth, radius_server_receive_auth,
data, NULL)) { data, NULL)) {
radius_server_deinit(data); goto fail;
return NULL;
} }
if (conf->acct_port) { if (conf->acct_port) {
@ -2285,20 +2289,20 @@ radius_server_init(struct radius_server_conf *conf)
data->acct_sock = radius_server_open_socket(conf->acct_port); data->acct_sock = radius_server_open_socket(conf->acct_port);
if (data->acct_sock < 0) { if (data->acct_sock < 0) {
wpa_printf(MSG_ERROR, "Failed to open UDP socket for RADIUS accounting server"); wpa_printf(MSG_ERROR, "Failed to open UDP socket for RADIUS accounting server");
radius_server_deinit(data); goto fail;
return NULL;
} }
if (eloop_register_read_sock(data->acct_sock, if (eloop_register_read_sock(data->acct_sock,
radius_server_receive_acct, radius_server_receive_acct,
data, NULL)) { data, NULL))
radius_server_deinit(data); goto fail;
return NULL;
}
} else { } else {
data->acct_sock = -1; data->acct_sock = -1;
} }
return data; return data;
fail:
radius_server_deinit(data);
return NULL;
} }