Skip to content

Commit db90fc9

Browse files
committed
server config UPDATE replace assert with else
1 parent cda4ae6 commit db90fc9

File tree

1 file changed

+44
-23
lines changed

1 file changed

+44
-23
lines changed

src/server_config.c

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -889,9 +889,11 @@ config_hostkey_pubkey_inline(const struct lyd_node *node, enum nc_operation pare
889889
NC_CHECK_RET(config_cleartext_privkey_data(cleartext, op, &hostkey->key.privkey));
890890
} else if (hidden) {
891891
NC_CHECK_RET(config_hidden_privkey_data(hidden, op));
892-
} else {
893-
assert(encrypted);
892+
} else if (encrypted) {
894893
NC_CHECK_RET(config_encrypted_privkey_data(encrypted, op));
894+
} else {
895+
ERR(NULL, "Invalid YANG data provided.");
896+
return 1;
895897
}
896898

897899
if (op == NC_OP_DELETE) {
@@ -937,9 +939,11 @@ config_hostkey_public_key(const struct lyd_node *node, enum nc_operation parent_
937939
NC_CHECK_RET(nc_lyd_find_child(node, "central-keystore-reference", 0, &keystore_ref));
938940
if (inline_def) {
939941
NC_CHECK_RET(config_hostkey_pubkey_inline(inline_def, op, hostkey));
940-
} else {
941-
assert(keystore_ref);
942+
} else if (keystore_ref) {
942943
NC_CHECK_RET(config_hostkey_pubkey_keystore(keystore_ref, op, hostkey));
944+
} else {
945+
ERR(NULL, "Invalid YANG data provided.");
946+
return 1;
943947
}
944948

945949
return 0;
@@ -991,10 +995,12 @@ config_ssh_hostkey(const struct lyd_node *node, enum nc_operation parent_op, str
991995
if (public_key) {
992996
/* config public key */
993997
NC_CHECK_RET(config_hostkey_public_key(public_key, op, hostkey));
994-
} else {
998+
} else if (certificate) {
995999
/* config certificate */
996-
assert(certificate);
9971000
NC_CHECK_RET(config_hostkey_certificate(certificate, op));
1001+
} else {
1002+
ERR(NULL, "Invalid YANG data provided.");
1003+
return 1;
9981004
}
9991005

10001006
/* all children processed, we can now delete the hostkey */
@@ -1219,9 +1225,11 @@ config_ssh_user_public_keys(const struct lyd_node *node, enum nc_operation paren
12191225
NC_CHECK_RET(config_ssh_user_pubkey_inline(inline_def, op, user));
12201226
} else if (truststore_ref) {
12211227
NC_CHECK_RET(config_ssh_user_pubkey_truststore(truststore_ref, op, user));
1222-
} else {
1223-
assert(system);
1228+
} else if (system) {
12241229
NC_CHECK_RET(config_ssh_user_pubkey_system(system, op, user));
1230+
} else {
1231+
ERR(NULL, "Invalid YANG data provided.");
1232+
return 1;
12251233
}
12261234

12271235
return 0;
@@ -1942,9 +1950,11 @@ config_tls_server_ident_cert_inline(const struct lyd_node *node, enum nc_operati
19421950
NC_CHECK_RET(config_cleartext_privkey_data(cleartext, op, &opts->local.key.privkey), 1);
19431951
} else if (hidden) {
19441952
NC_CHECK_RET(config_hidden_privkey_data(hidden, op), 1);
1945-
} else {
1946-
assert(encrypted);
1953+
} else if (encrypted) {
19471954
NC_CHECK_RET(config_encrypted_privkey_data(encrypted, op), 1);
1955+
} else {
1956+
ERR(NULL, "Invalid YANG data provided.");
1957+
return 1;
19481958
}
19491959

19501960
/* config certificate data */
@@ -2055,9 +2065,11 @@ config_tls_server_ident_certificate(const struct lyd_node *node, enum nc_operati
20552065
NC_CHECK_RET(nc_lyd_find_child(node, "central-keystore-reference", 0, &keystore_ref));
20562066
if (inline_def) {
20572067
NC_CHECK_RET(config_tls_server_ident_cert_inline(inline_def, op, tls));
2058-
} else {
2059-
assert(keystore_ref);
2068+
} else if (keystore_ref) {
20602069
NC_CHECK_RET(config_tls_server_ident_cert_keystore(keystore_ref, op, tls));
2070+
} else {
2071+
ERR(NULL, "Invalid YANG data provided.");
2072+
return 1;
20612073
}
20622074

20632075
return 0;
@@ -2103,9 +2115,11 @@ config_tls_server_identity(const struct lyd_node *node, enum nc_operation parent
21032115
NC_CHECK_RET(config_tls_server_ident_raw_key(raw_private_key, op));
21042116
} else if (tls12_psk) {
21052117
NC_CHECK_RET(config_tls_server_ident_tls12_psk(tls12_psk, op));
2106-
} else {
2107-
assert(tls13_epsk);
2118+
} else if (tls13_epsk) {
21082119
NC_CHECK_RET(config_tls_server_ident_tls13_epsk(tls13_epsk, op));
2120+
} else {
2121+
ERR(NULL, "Invalid YANG data provided.");
2122+
return 1;
21092123
}
21102124

21112125
return 0;
@@ -2243,9 +2257,11 @@ config_tls_client_auth_ca_certs(const struct lyd_node *node, enum nc_operation p
22432257
NC_CHECK_RET(nc_lyd_find_child(node, "central-truststore-reference", 0, &truststore_ref), 1);
22442258
if (inline_def) {
22452259
NC_CHECK_RET(config_tls_client_auth_ca_certs_inline(inline_def, op, client_auth));
2246-
} else {
2247-
assert(truststore_ref);
2260+
} else if (truststore_ref) {
22482261
NC_CHECK_RET(config_tls_client_auth_ca_certs_truststore(truststore_ref, op, client_auth));
2262+
} else {
2263+
ERR(NULL, "Invalid YANG data provided.");
2264+
return 1;
22492265
}
22502266

22512267
return 0;
@@ -2365,9 +2381,11 @@ config_tls_client_auth_ee_certs(const struct lyd_node *node,
23652381
NC_CHECK_RET(nc_lyd_find_child(node, "central-truststore-reference", 0, &truststore_ref), 1);
23662382
if (inline_def) {
23672383
NC_CHECK_RET(config_tls_client_auth_ee_certs_inline(inline_def, op, client_auth));
2368-
} else {
2369-
assert(truststore_ref);
2384+
} else if (truststore_ref) {
23702385
NC_CHECK_RET(config_tls_client_auth_ee_certs_truststore(truststore_ref, op, client_auth));
2386+
} else {
2387+
ERR(NULL, "Invalid YANG data provided.");
2388+
return 1;
23712389
}
23722390

23732391
return 0;
@@ -3197,9 +3215,11 @@ config_unix(const struct lyd_node *node, enum nc_operation parent_op, struct nc_
31973215
NC_CHECK_RET(nc_lyd_find_child(node, "hidden-path", 0, &hidden_path));
31983216
if (socket_path) {
31993217
NC_CHECK_RET(config_unix_socket_path(socket_path, op, endpt));
3200-
} else {
3201-
assert(hidden_path);
3218+
} else if (hidden_path) {
32023219
NC_CHECK_RET(config_unix_hidden_path(hidden_path, op, endpt));
3220+
} else {
3221+
ERR(NULL, "Invalid YANG data provided.");
3222+
return 1;
32033223
}
32043224

32053225
/* config socket permissions */
@@ -3279,7 +3299,6 @@ config_endpoint(const struct lyd_node *node, enum nc_operation parent_op,
32793299
NC_CHECK_RET(nc_lyd_find_child(node, "ssh", 0, &ssh));
32803300
NC_CHECK_RET(nc_lyd_find_child(node, "tls", 0, &tls));
32813301
NC_CHECK_RET(nc_lyd_find_child(node, "libnetconf2-netconf-server:unix", 0, &unix));
3282-
assert(ssh || tls || unix);
32833302

32843303
#ifdef NC_ENABLED_SSH_TLS
32853304
if (ssh) {
@@ -3618,9 +3637,11 @@ config_ch_client_endpoint(const struct lyd_node *node, enum nc_operation parent_
36183637
NC_CHECK_RET(nc_lyd_find_child(node, "tls", 0, &tls));
36193638
if (ssh) {
36203639
NC_CHECK_RET(config_ch_endpoint_ssh(ssh, op, endpt));
3621-
} else {
3622-
assert(tls);
3640+
} else if (tls) {
36233641
NC_CHECK_RET(config_ch_endpoint_tls(tls, op, endpt));
3642+
} else {
3643+
ERR(NULL, "Invalid YANG data provided.");
3644+
return 1;
36243645
}
36253646
#endif /* NC_ENABLED_SSH_TLS */
36263647

0 commit comments

Comments
 (0)