Skip to content

Commit 98c90ea

Browse files
committed
pcn-firewall: fix out of bound access in show rule
add test for indexes out of range Signed-off-by: Matteo Bertrone <m.bertrone@gmail.com>
1 parent f36e8ed commit 98c90ea

2 files changed

Lines changed: 75 additions & 1 deletion

File tree

src/services/pcn-firewall/src/Chain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ void Chain::delStatsList() {
511511
}
512512

513513
std::shared_ptr<ChainRule> Chain::getRule(const uint32_t &id) {
514-
if (rules_.size() < id || !rules_[id]) {
514+
if (rules_.size() <= id || !rules_[id]) {
515515
throw std::runtime_error("There is no rule " + id);
516516
}
517517
return rules_[id];
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# PING testing rule appending
2+
3+
source "${BASH_SOURCE%/*}/../helpers.bash"
4+
5+
function fwcleanup {
6+
set +e
7+
polycubectl firewall del fw
8+
delete_veth 2
9+
}
10+
trap fwcleanup EXIT
11+
12+
echo -e '\nTest wrong position \n'
13+
set -e
14+
set -x
15+
16+
create_veth 2
17+
18+
polycubectl firewall add fw loglevel=DEBUG
19+
polycubectl attach fw veth1
20+
21+
# INGRESS one rule
22+
polycubectl firewall fw chain INGRESS append src=10.0.0.1 dst=10.0.0.2 l4proto=ICMP action=FORWARD
23+
24+
#EGRESS multiple rules
25+
polycubectl firewall fw chain EGRESS append src=10.0.0.2/32 dst=10.0.0.1/32 l4proto=ICMP action=FORWARD
26+
polycubectl firewall fw chain EGRESS append src=10.0.0.2/32 dst=10.0.0.1/32 l4proto=ICMP action=FORWARD
27+
polycubectl firewall fw chain EGRESS append src=10.0.0.2/32 dst=10.0.0.1/32 l4proto=ICMP action=FORWARD
28+
polycubectl firewall fw chain EGRESS append src=10.0.0.2/32 dst=10.0.0.1/32 l4proto=ICMP action=FORWARD
29+
30+
# Test out of bound access
31+
set +e
32+
polycubectl fw chain EGRESS rule del -1
33+
polycubectl fw chain EGRESS rule del 4
34+
polycubectl fw chain EGRESS rule del 5
35+
polycubectl fw chain EGRESS rule del 10
36+
set -e
37+
38+
# test fw to be still alive
39+
polycubectl fw chain EGRESS show
40+
41+
set +e
42+
polycubectl fw chain EGRESS rule show -1
43+
polycubectl fw chain EGRESS rule show 4
44+
polycubectl fw chain EGRESS rule show 5
45+
polycubectl fw chain EGRESS rule show 10
46+
set -e
47+
48+
# test fw to be still alive
49+
polycubectl fw chain EGRESS show
50+
51+
set +e
52+
polycubectl fw chain INGRESS rule del -1
53+
polycubectl fw chain INGRESS rule del 1
54+
polycubectl fw chain INGRESS rule del 2
55+
polycubectl fw chain INGRESS rule del 10
56+
57+
polycubectl fw chain INGRESS rule show -1
58+
polycubectl fw chain INGRESS rule show 1
59+
polycubectl fw chain INGRESS rule show 2
60+
polycubectl fw chain INGRESS rule show 10
61+
set -e
62+
63+
# test fw to be still alive
64+
polycubectl fw chain EGRESS show
65+
66+
polycubectl fw chain EGRESS show rule 0
67+
polycubectl fw chain EGRESS show rule 1
68+
polycubectl fw chain EGRESS show rule 2
69+
polycubectl fw chain EGRESS show rule 3
70+
71+
polycubectl fw chain INGRESS show rule 0
72+
73+
74+

0 commit comments

Comments
 (0)