aboutsummaryrefslogtreecommitdiff
path: root/networking
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2019-04-28 17:55:27 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2019-04-28 17:55:27 +0200
commit405095d84b1f3be17efb4e10d87d480bd054877f (patch)
tree2af92e403edf9ef0f0afe072ad6f70c63fd24d5a /networking
parent7b93e317c13053e40e76cc5c36404f92d05dd41c (diff)
downloadbusybox-405095d84b1f3be17efb4e10d87d480bd054877f.tar.gz
ifupdown: close memory leak
function old new delta execute_all 80 91 +11 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking')
-rw-r--r--networking/ifupdown.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/networking/ifupdown.c b/networking/ifupdown.c
index 8a6efc976..5327b0979 100644
--- a/networking/ifupdown.c
+++ b/networking/ifupdown.c
@@ -1177,8 +1177,15 @@ static int doit(char *str)
static int execute_all(struct interface_defn_t *ifd, const char *opt)
{
+ /* 'opt' is always short, the longest value is "post-down".
+ * Can use on-stack buffer instead of xasprintf'ed one.
+ */
+ char buf[sizeof("run-parts /etc/network/if-%s.d")
+ + sizeof("post-down")
+ /*paranoia:*/ + 8
+ ];
int i;
- char *buf;
+
for (i = 0; i < ifd->n_options; i++) {
if (strcmp(ifd->option[i].name, opt) == 0) {
if (!doit(ifd->option[i].value)) {
@@ -1192,8 +1199,7 @@ static int execute_all(struct interface_defn_t *ifd, const char *opt)
* complains, and this message _is_ annoyingly visible.
* Don't "fix" this (unless newer Debian does).
*/
- buf = xasprintf("run-parts /etc/network/if-%s.d", opt);
- /* heh, we don't bother free'ing it */
+ sprintf(buf, "run-parts /etc/network/if-%s.d", opt);
return doit(buf);
}