From aff192cda38b56180dd00e90702e46ecd5fc1465 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Wed, 29 Jan 2025 20:12:51 +0100 Subject: [PATCH] ubus: hide local private key in network_get Private key should only be written, not returned Signed-off-by: Felix Fietkau --- network.c | 20 +++++++++++++++++--- network.h | 1 + ubus.c | 6 +++--- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/network.c b/network.c index 721d48e..09fd01b 100644 --- a/network.c +++ b/network.c @@ -585,6 +585,21 @@ network_destroy(struct network *net) free(net); } +void network_get_config(struct network *net, struct blob_buf *buf) +{ + struct blob_attr *tb[__NETWORK_ATTR_MAX]; + + if (!net->config.data) + return; + + blobmsg_parse_attr(network_policy, __NETWORK_ATTR_MAX, tb, + net->config.data); + tb[NETWORK_ATTR_KEY] = NULL; + for (size_t i = 0; i < ARRAY_SIZE(tb); i++) + if (tb[i]) + blobmsg_add_blob(buf, tb[i]); +} + static int network_set_config(struct network *net, struct blob_attr *config) { @@ -600,9 +615,8 @@ network_set_config(struct network *net, struct blob_attr *config) memset(&net->config, 0, sizeof(net->config)); net->config.data = blob_memdup(config); - blobmsg_parse(network_policy, __NETWORK_ATTR_MAX, tb, - blobmsg_data(net->config.data), - blobmsg_len(net->config.data)); + blobmsg_parse_attr(network_policy, __NETWORK_ATTR_MAX, tb, + net->config.data); if ((cur = tb[NETWORK_ATTR_TYPE]) == NULL || !strlen(blobmsg_get_string(cur)) || diff --git a/network.h b/network.h index f713fd3..aa45b6b 100644 --- a/network.h +++ b/network.h @@ -102,6 +102,7 @@ static inline const char *network_name(struct network *net) return net->node.key; } +void network_get_config(struct network *net, struct blob_buf *buf); bool network_skip_endpoint_route(struct network *net, union network_endpoint *ep); void network_fill_host_addr(union network_addr *addr, uint8_t *key); int network_save_dynamic(struct network *net); diff --git a/ubus.c b/ubus.c index 6e289da..11bacc2 100644 --- a/ubus.c +++ b/ubus.c @@ -58,9 +58,9 @@ __network_dump(struct blob_buf *buf, struct network *net) void *c, *p; char *str; - blobmsg_add_field(buf, BLOBMSG_TYPE_TABLE, "config", - blobmsg_data(net->config.data), - blobmsg_len(net->config.data)); + c = blobmsg_open_table(buf, "config"); + network_get_config(net, buf); + blobmsg_close_table(buf, c); if (local) blobmsg_add_string(buf, "local_host", network_host_name(local)); -- 2.30.2