[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 1/5] net: Clarify early exit condition
From: |
Markus Armbruster |
Subject: |
[PULL 1/5] net: Clarify early exit condition |
Date: |
Thu, 28 Jan 2021 08:45:02 +0100 |
From: Eric Blake <eblake@redhat.com>
On first glance, the loop in qmp_query_rx_filter() has early return
paths that could leak any allocation of filter_list from a previous
iteration. But on closer inspection, it is obvious that all of the
early exits are guarded by has_name, and that the bulk of the loop
body can be executed at most once if the user is filtering by name,
thus, any early exit coincides with an empty list. Add asserts to
make this obvious.
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20210113221013.390592-2-eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
net/net.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/net/net.c b/net/net.c
index c1cd9c75f6..2afac24b79 100644
--- a/net/net.c
+++ b/net/net.c
@@ -1227,6 +1227,7 @@ RxFilterInfoList *qmp_query_rx_filter(bool has_name,
const char *name,
if (nc->info->type != NET_CLIENT_DRIVER_NIC) {
if (has_name) {
error_setg(errp, "net client(%s) isn't a NIC", name);
+ assert(!filter_list);
return NULL;
}
continue;
@@ -1252,6 +1253,7 @@ RxFilterInfoList *qmp_query_rx_filter(bool has_name,
const char *name,
} else if (has_name) {
error_setg(errp, "net client(%s) doesn't support"
" rx-filter querying", name);
+ assert(!filter_list);
return NULL;
}
--
2.26.2
- [PULL 0/5] QAPI patches patches for 2021-01-28, Markus Armbruster, 2021/01/28
- [PULL 3/5] qapi: Introduce QAPI_LIST_APPEND, Markus Armbruster, 2021/01/28
- [PULL 1/5] net: Clarify early exit condition,
Markus Armbruster <=
- [PULL 2/5] qapi: A couple more QAPI_LIST_PREPEND() stragglers, Markus Armbruster, 2021/01/28
- [PULL 5/5] qapi: More complex uses of QAPI_LIST_APPEND, Markus Armbruster, 2021/01/28
- [PULL 4/5] qapi: Use QAPI_LIST_APPEND in trivial cases, Markus Armbruster, 2021/01/28
- Re: [PULL 0/5] QAPI patches patches for 2021-01-28, Peter Maydell, 2021/01/29