From 296ed880132c5d3f20d84b1ffea9959d8d6be76b Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Mon, 16 Jul 2012 10:23:58 -0700 Subject: [PATCH] ovs-ofctl: Fix use-after-free error. Commit 4ce9c31573 (ovs-ofctl: Factor code out of read_flows_from_switch().) introduced a use-after-free error, fixed by this change. Also adds a unit test for "ovs-ofctl diff-flows" that would have found the problem. (The bug report cited "diff-flows" but this bug was present in dump-flows as well because they share common code.) Bug #12461. Reported-by: James Schmidt Signed-off-by: Ben Pfaff --- tests/ovs-ofctl.at | 32 ++++++++++++++++++++++++++++++++ utilities/ovs-ofctl.c | 1 + 2 files changed, 33 insertions(+) diff --git a/tests/ovs-ofctl.at b/tests/ovs-ofctl.at index d456734b..7233a669 100644 --- a/tests/ovs-ofctl.at +++ b/tests/ovs-ofctl.at @@ -1446,3 +1446,35 @@ AT_CHECK( ]) OVS_VSWITCHD_STOP AT_CLEANUP + +AT_SETUP([ovs-ofctl diff-flows]) +OVS_VSWITCHD_START + +# Prints the integers from $1 to $2, increasing by $3 (default 1) on stdout. +seq () { + while test $1 -le $2; do + echo $1 + set `expr $1 + ${3-1}` $2 $3 + done +} + +# Add tons of flows to br0. +for i in `seq 0 1023`; do echo "dl_vlan=$i,actions=drop"; done > add-flows.txt +AT_CHECK([ovs-ofctl add-flows br0 add-flows.txt]) + +# Dump them and compare against what we expect by hand, then with diff-flows. +for i in `seq 0 1023`; do echo " dl_vlan=$i actions=drop"; done | sort > expout +AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sed '/NXST_FLOW/d' | sort], + [0], [expout]) +AT_CHECK([ovs-ofctl diff-flows br0 add-flows.txt]) + +# Remove even-numbered flows, compare again. +for i in `seq 0 1023 2`; do echo "dl_vlan=$i"; done > del-flows.txt +AT_CHECK([ovs-ofctl del-flows br0 - < del-flows.txt]) +for i in `seq 0 1023 2`; do echo "+dl_vlan=$i actions=drop"; done | sort > expout +AT_CHECK([ovs-ofctl diff-flows br0 add-flows.txt | sort], [0], [expout]) +for i in `seq 0 1023 2`; do echo "-dl_vlan=$i actions=drop"; done | sort > expout +AT_CHECK([ovs-ofctl diff-flows add-flows.txt br0 | sort], [0], [expout]) + +OVS_VSWITCHD_STOP +AT_CLEANUP diff --git a/utilities/ovs-ofctl.c b/utilities/ovs-ofctl.c index f925d846..4ad1acb4 100644 --- a/utilities/ovs-ofctl.c +++ b/utilities/ovs-ofctl.c @@ -1903,6 +1903,7 @@ recv_flow_stats_reply(struct vconn *vconn, ovs_be32 send_xid, case EOF: flags = ((const struct ofp_stats_msg *) reply->l2)->flags; ofpbuf_delete(reply); + reply = NULL; if (!(flags & htons(OFPSF_REPLY_MORE))) { *replyp = NULL; return false; -- 2.30.2