[LEDE-DEV,1/7] firewall3: check the return value of fw3_parse_options()

Message ID 1492704342-24042-1-git-send-email-pme.lebleu@gmail.com
State Changes Requested
Headers show

Commit Message

Pierre Lebleu April 20, 2017, 4:05 p.m.
The return value of fw3_parse_options() should be checked and
when it fails the section should be skipped.

Signed-off-by: Pierre Lebleu <pme.lebleu@gmail.com>
---
 defaults.c |    6 +++++-
 forwards.c |    7 ++++++-
 includes.c |    7 ++++++-
 ipsets.c   |    7 ++++++-
 zones.c    |    7 ++++++-
 5 files changed, 29 insertions(+), 5 deletions(-)

Patch

diff --git a/defaults.c b/defaults.c
index 8afbf9a..37e6e0f 100644
--- a/defaults.c
+++ b/defaults.c
@@ -107,7 +107,11 @@  fw3_load_defaults(struct fw3_state *state, struct uci_package *p)
 			continue;
 		}
 
-		fw3_parse_options(&state->defaults, fw3_flag_opts, s);
+		if(!fw3_parse_options(&state->defaults, fw3_flag_opts, s))
+		{
+			warn_elem(e, "skipped due to invalid options");
+			continue;
+		}
 
 		check_policy(e, &defs->policy_input, "input");
 		check_policy(e, &defs->policy_output, "output");
diff --git a/forwards.c b/forwards.c
index 997c307..cf0c3a8 100644
--- a/forwards.c
+++ b/forwards.c
@@ -54,7 +54,12 @@  fw3_load_forwards(struct fw3_state *state, struct uci_package *p)
 
 		forward->enabled = true;
 
-		fw3_parse_options(forward, fw3_forward_opts, s);
+		if (!fw3_parse_options(forward, fw3_forward_opts, s))
+		{
+			warn_elem(e, "skipped due to invalid options");
+			fw3_free_forward(forward);
+			continue;
+		}
 
 		if (!forward->enabled)
 		{
diff --git a/includes.c b/includes.c
index a9a75cb..7ca164f 100644
--- a/includes.c
+++ b/includes.c
@@ -54,7 +54,12 @@  fw3_load_includes(struct fw3_state *state, struct uci_package *p)
 		include->name = e->name;
 		include->enabled = true;
 
-		fw3_parse_options(include, fw3_include_opts, s);
+		if (!fw3_parse_options(include, fw3_include_opts, s))
+		{
+			warn_elem(e, "skipped due to invalid options");
+			fw3_free_include(include);
+			continue;
+		}
 
 		if (!include->enabled)
 		{
diff --git a/ipsets.c b/ipsets.c
index 0325944..3b1ba00 100644
--- a/ipsets.c
+++ b/ipsets.c
@@ -239,7 +239,12 @@  fw3_load_ipsets(struct fw3_state *state, struct uci_package *p)
 		if (!ipset)
 			continue;
 
-		fw3_parse_options(ipset, fw3_ipset_opts, s);
+		if (!fw3_parse_options(ipset, fw3_ipset_opts, s))
+		{
+			warn_elem(e, "skipped due to invalid options");
+			fw3_free_ipset(ipset);
+			continue;
+		}
 
 		if (ipset->external)
 		{
diff --git a/zones.c b/zones.c
index 520d00c..1b47e15 100644
--- a/zones.c
+++ b/zones.c
@@ -170,7 +170,12 @@  fw3_load_zones(struct fw3_state *state, struct uci_package *p)
 		if (!zone)
 			continue;
 
-		fw3_parse_options(zone, fw3_zone_opts, s);
+		if (!fw3_parse_options(zone, fw3_zone_opts, s))
+		{
+			warn_elem(e, "skipped due to invalid options");
+			fw3_free_zone(zone);
+			continue;
+		}
 
 		if (!zone->enabled)
 		{