summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Härdeman2025-11-23 13:50:00 +0000
committerÁlvaro Fernández Rojas2025-11-27 07:24:38 +0000
commitadb2b8a1afffd805753dcc2e52c4764028116676 (patch)
treeff8d697f5549d34d9290bf13c5d38dbaf610cd77
parentb4ab371c541ab481c7dff001964afd621b5a968d (diff)
downloadodhcpd-adb2b8a1afffd805753dcc2e52c4764028116676.tar.gz
config: fix realloc() handling for the "upstream" option
Deal properly with realloc() failure. Signed-off-by: David Härdeman <david@hardeman.nu> Link: https://github.com/openwrt/odhcpd/pull/320 Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
-rw-r--r--src/config.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/config.c b/src/config.c
index 9a09224..6a87960 100644
--- a/src/config.c
+++ b/src/config.c
@@ -1227,16 +1227,17 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr
if (overwrite && (c = tb[IFACE_ATTR_UPSTREAM])) {
struct blob_attr *cur;
unsigned rem;
+ char *tmp;
blobmsg_for_each_attr(cur, c, rem) {
if (blobmsg_type(cur) != BLOBMSG_TYPE_STRING || !blobmsg_check_attr(cur, false))
continue;
- iface->upstream = realloc(iface->upstream,
- iface->upstream_len + blobmsg_data_len(cur));
- if (!iface->upstream)
+ tmp = realloc(iface->upstream, iface->upstream_len + blobmsg_data_len(cur));
+ if (!tmp)
goto err;
+ iface->upstream = tmp;
memcpy(iface->upstream + iface->upstream_len, blobmsg_get_string(cur), blobmsg_data_len(cur));
iface->upstream_len += blobmsg_data_len(cur);
}