Skip to content

Commit 1ed9887

Browse files
gfreewindummakynes
authored andcommitted
netfilter: xt_multiport: Fix wrong unmatch result with multiple ports
I lost one test case in the last commit for xt_multiport. For example, the rule is "-m multiport --dports 22,80,443". When first port is unmatched and the second is matched, the curent codes could not return the right result. It would return false directly when the first port is unmatched. Fixes: dd2602d ("netfilter: xt_multiport: Use switch case instead of multiple condition checks") Signed-off-by: Gao Feng <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent 1814096 commit 1ed9887

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

net/netfilter/xt_multiport.c

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,18 @@ ports_match_v1(const struct xt_multiport_v1 *minfo,
4444

4545
switch (minfo->flags) {
4646
case XT_MULTIPORT_SOURCE:
47-
return (src >= s && src <= e) ^ minfo->invert;
47+
if (src >= s && src <= e)
48+
return true ^ minfo->invert;
49+
break;
4850
case XT_MULTIPORT_DESTINATION:
49-
return (dst >= s && dst <= e) ^ minfo->invert;
51+
if (dst >= s && dst <= e)
52+
return true ^ minfo->invert;
53+
break;
5054
case XT_MULTIPORT_EITHER:
51-
return ((dst >= s && dst <= e) ||
52-
(src >= s && src <= e)) ^ minfo->invert;
55+
if ((dst >= s && dst <= e) ||
56+
(src >= s && src <= e))
57+
return true ^ minfo->invert;
58+
break;
5359
default:
5460
break;
5561
}
@@ -59,11 +65,17 @@ ports_match_v1(const struct xt_multiport_v1 *minfo,
5965

6066
switch (minfo->flags) {
6167
case XT_MULTIPORT_SOURCE:
62-
return (src == s) ^ minfo->invert;
68+
if (src == s)
69+
return true ^ minfo->invert;
70+
break;
6371
case XT_MULTIPORT_DESTINATION:
64-
return (dst == s) ^ minfo->invert;
72+
if (dst == s)
73+
return true ^ minfo->invert;
74+
break;
6575
case XT_MULTIPORT_EITHER:
66-
return (src == s || dst == s) ^ minfo->invert;
76+
if (src == s || dst == s)
77+
return true ^ minfo->invert;
78+
break;
6779
default:
6880
break;
6981
}

0 commit comments

Comments
 (0)