diff options
| author | David Härdeman | 2025-11-23 13:50:00 +0000 |
|---|---|---|
| committer | Álvaro Fernández Rojas | 2025-11-27 07:24:38 +0000 |
| commit | adb2b8a1afffd805753dcc2e52c4764028116676 (patch) | |
| tree | ff8d697f5549d34d9290bf13c5d38dbaf610cd77 | |
| parent | b4ab371c541ab481c7dff001964afd621b5a968d (diff) | |
| download | odhcpd-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.c | 7 |
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); } |