ebtables: Remove PATH_MAX sized stack allocation

This commit is contained in:
Matthias Bolte 2011-04-03 11:21:16 +02:00
parent 57162db82c
commit 859efe7f88

View File

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