iptables: Fix crash on malformed iptables-restore
PATCH 1/1 iptables: Fix crash on malformed iptables-restore
Fixes the crash reported in Bugzilla #1131 where a malformed parameter that specifies the table option can create an invalid pointer.
Improves the tables option check to find a beginning '-' followed by a 't' anywhere in the parameter.
--- iptables/ip6tables-restore.c | 3 +-- iptables/iptables-restore.c | 3 +-- iptables/iptables-xml.c | 10 ++++------ iptables/xtables-restore.c | 3 +-- 4 files changed, 7 insertions(+), 12 deletions(-)
iptables/ip6tables-restore.c +1 -2
@@ -165,8 +165,7 @@ static void add_param_to_argv(char *parsestart) param_buffer[param_len] ='\0' ;/* check if table name specified */ -if (!strncmp (param_buffer,"-t" ,2 ) - || !strncmp (param_buffer,"--table" ,8 )) { +if (param_buffer[0 ] =='-' &&strchr (param_buffer,'t' )) {xtables_error (PARAMETER_PROBLEM ,"The -t option (seen in line %u) cannot be " "used in ip6tables-restore.\n" , line);
iptables/iptables-restore.c +1 -2
@@ -162,8 +162,7 @@ static void add_param_to_argv(char *parsestart) param_buffer[param_len] ='\0' ;/* check if table name specified */ -if (!strncmp (param_buffer,"-t" ,2 ) - || !strncmp (param_buffer,"--table" ,8 )) { +if (param_buffer[0 ] =='-' &&strchr (param_buffer,'t' )) {xtables_error (PARAMETER_PROBLEM ,"The -t option (seen in line %u) cannot be " "used in iptables-restore.\n" , line);
iptables/iptables-xml.c +4 -6
@@ -819,13 +819,11 @@ iptables_xml_main(int argc, char *argv[]) *(param_buffer + param_len) ='\0' ;/* check if table name specified */ -if (!strncmp (param_buffer,"-t" ,3 ) - || !strncmp (param_buffer, -"--table" ,8 )) { +if (param_buffer[0 ] =='-' &&strchr (param_buffer,'t' )) {xtables_error (PARAMETER_PROBLEM , -"Line %u seems to have a " -"-t table option.\n" , - line); +"Line %u seems to have a " +"-t table option.\n" , + line);exit (1 ); }
iptables/xtables-restore.c +1 -2
@@ -136,8 +136,7 @@ static void add_param_to_argv(char *parsestart) param_buffer[param_len] ='\0' ;/* check if table name specified */ -if (!strncmp (param_buffer,"-t" ,2 ) - || !strncmp (param_buffer,"--table" ,8 )) { +if (param_buffer[0 ] =='-' &&strchr (param_buffer,'t' )) {xtables_error (PARAMETER_PROBLEM ,"The -t option (seen in line %u) cannot be " "used in xtables-restore.\n" , line);
Signature · 1 line
2.11.0
Florian Westphal
maintainerQuoted 12 lines · Oliver Ford
Fixes the crash reported in Bugzilla #1131 where a malformed parameter that specifies the table option can create an invalid pointer.
Improves the tables option check to find a beginning '-' followed by a 't' anywhere in the parameter.
iptables/iptables-restore.c +0
-0
iptables/iptables-restore.c static void add_param_to_argv(char *parsestart) · line 168
Quoted 9 lines
iptables/iptables-restore.c +1
-2@@ -162,8 +162,7 @@ static void add_param_to_argv(char *parsestart) param_buffer[param_len] ='\0' ;/* check if table name specified */ -if (!strncmp (param_buffer,"-t" ,2 ) - || !strncmp (param_buffer,"--table" ,8 )) { +if (param_buffer[0 ] =='-' &&strchr (param_buffer,'t' )) {xtables_error (PARAMETER_PROBLEM ,"The -t option (seen in line %u) cannot be " "used in iptables-restore.\n" , line);
strchr() can only called if param_buffer[1] != '-', else this breaks something like:
# Generated by iptables-save v1.6.0 on Thu May 18 00:00:38 2017 *filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
--delete foo
COMMIT
(use '-n' option to iptables).
Quoted 34 lines · Florian Westphal
Quoted 12 lines · Oliver Ford
Fixes the crash reported in Bugzilla #1131 where a malformed parameter that specifies the table option can create an invalid pointer.
Improves the tables option check to find a beginning '-' followed by a 't' anywhere in the parameter.
iptables/iptables-restore.c +0
-0iptables/iptables-restore.c static void add_param_to_argv(char *parsestart) · line 168
Quoted 9 lines
iptables/iptables-restore.c +1
-2@@ -162,8 +162,7 @@ static void add_param_to_argv(char *parsestart) param_buffer[param_len] ='\0' ;/* check if table name specified */ -if (!strncmp (param_buffer,"-t" ,2 ) - || !strncmp (param_buffer,"--table" ,8 )) { +if (param_buffer[0 ] =='-' &&strchr (param_buffer,'t' )) {xtables_error (PARAMETER_PROBLEM ,"The -t option (seen in line %u) cannot be " "used in iptables-restore.\n" , line);
strchr()can only called if param_buffer[1] != '-', else this breaks something like:# Generated by iptables-save v1.6.0 on Thu May 18 00:00:38 2017 *filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
--delete foo
COMMIT
Quoted 1 line
(use '-n' option to iptables).
Good point I'll check for that and send an updated patch.
Florian Westphal
maintainerQuoted 35 lines · Oliver Ford
Quoted 34 lines · Florian Westphal
Quoted 12 lines · Oliver Ford
Fixes the crash reported in Bugzilla #1131 where a malformed parameter that specifies the table option can create an invalid pointer.
Improves the tables option check to find a beginning '-' followed by a 't' anywhere in the parameter.
iptables/iptables-restore.c +0
-0iptables/iptables-restore.c static void add_param_to_argv(char *parsestart) · line 168
Quoted 9 lines
iptables/iptables-restore.c +1
-2@@ -162,8 +162,7 @@ static void add_param_to_argv(char *parsestart) param_buffer[param_len] ='\0' ;/* check if table name specified */ -if (!strncmp (param_buffer,"-t" ,2 ) - || !strncmp (param_buffer,"--table" ,8 )) { +if (param_buffer[0 ] =='-' &&strchr (param_buffer,'t' )) {xtables_error (PARAMETER_PROBLEM ,"The -t option (seen in line %u) cannot be " "used in iptables-restore.\n" , line);
strchr()can only called if param_buffer[1] != '-', else this breaks something like:# Generated by iptables-save v1.6.0 on Thu May 18 00:00:38 2017 *filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
--delete foo
COMMIT
Quoted 3 lines
Quoted 1 line
(use '-n' option to iptables).
Good point I'll check for that and send an updated patch.
Forgot to mention: Would be nice to explain in the commit message why this is needed, e.g. -nt, --tab, etc. are not caught by current test.