[PATCH 03/20] ebtables: Remove PATH_MAX sized stack allocation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
 src/util/ebtables.c |   44 +++++++++++++++++++++++++++++---------------
 1 files changed, 29 insertions(+), 15 deletions(-)

diff --git a/src/util/ebtables.c b/src/util/ebtables.c
index e3b8da4..27dce5d 100644
--- a/src/util/ebtables.c
+++ b/src/util/ebtables.c
@@ -266,29 +266,43 @@ ebtablesAddRemoveRule(ebtRules *rules, int action, const char *arg, ...)
 ebtablesContext *
 ebtablesContextNew(const char *driver)
 {
-    ebtablesContext *ctx;
-    char chain[PATH_MAX];
+    bool success = false;
+    ebtablesContext *ctx = NULL;
+    char *input_chain = NULL;
+    char *forward_chain = NULL;
+    char *nat_chain = NULL;
 
     if (VIR_ALLOC(ctx) < 0)
         return NULL;
 
-    snprintf(chain, sizeof(chain), "libvirt_%s_INPUT", driver);
-    if (!(ctx->input_filter = ebtRulesNew("filter", chain)))
-        goto error;
+    if (virAsprintf(&input_chain, "libvirt_%s_INPUT", driver) < 0 ||
+        virAsprintf(&forward_chain, "libvirt_%s_FORWARD", driver) < 0 ||
+        virAsprintf(&nat_chain, "libvirt_%s_POSTROUTING", driver) < 0) {
+        goto cleanup;
+    }
 
-    snprintf(chain, sizeof(chain), "libvirt_%s_FORWARD", driver);
-    if (!(ctx->forward_filter = ebtRulesNew("filter", chain)))
-        goto error;
+    if (!(ctx->input_filter = ebtRulesNew("filter", input_chain)))
+        goto cleanup;
 
-    snprintf(chain, sizeof(chain), "libvirt_%s_POSTROUTING", driver);
-    if (!(ctx->nat_postrouting = ebtRulesNew("nat", chain)))
-        goto error;
+    if (!(ctx->forward_filter = ebtRulesNew("filter", forward_chain)))
+        goto cleanup;
 
-    return ctx;
+    if (!(ctx->nat_postrouting = ebtRulesNew("nat", nat_chain)))
+        goto cleanup;
 
- error:
-    ebtablesContextFree(ctx);
-    return NULL;
+    success = true;
+
+cleanup:
+    VIR_FREE(input_chain);
+    VIR_FREE(forward_chain);
+    VIR_FREE(nat_chain);
+
+    if (!success) {
+        ebtablesContextFree(ctx);
+        ctx = NULL;
+    }
+
+    return ctx;
 }
 
 /**
-- 
1.7.0.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]