From: Eric Blake <eblake@redhat.com>
To: qemu-devel@nongnu.org
Cc: Jason Wang <jasowang@redhat.com>, armbru@redhat.com
Subject: [PATCH v3 1/7] net: Clarify early exit condition
Date: Wed, 23 Dec 2020 16:10:56 -0600 [thread overview]
Message-ID: <20201223221102.390740-2-eblake@redhat.com> (raw)
In-Reply-To: <20201223221102.390740-1-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>
---
net/net.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/net/net.c b/net/net.c
index e1035f21d183..e581c8a26868 100644
--- a/net/net.c
+++ b/net/net.c
@@ -1211,6 +1211,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;
@@ -1236,6 +1237,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.29.2
next prev parent reply other threads:[~2020-12-23 22:17 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-23 22:10 [PATCH v3 0/7] Common macros for QAPI list growth Eric Blake
2020-12-23 22:10 ` Eric Blake [this message]
2021-01-13 12:57 ` [PATCH v3 1/7] net: Clarify early exit condition Markus Armbruster
2020-12-23 22:10 ` [PATCH v3 2/7] rocker: Revamp fp_port_get_info Eric Blake
2021-01-13 12:57 ` Markus Armbruster
2020-12-23 22:10 ` [PATCH v3 3/7] migration: Refactor migrate_cap_add Eric Blake
2021-01-13 12:58 ` Markus Armbruster
2020-12-23 22:10 ` [PATCH v3 4/7] qapi: Use QAPI_LIST_PREPEND() where possible Eric Blake
2021-01-13 13:00 ` Markus Armbruster
2020-12-23 22:11 ` [PATCH v3 5/7] qapi: Introduce QAPI_LIST_APPEND Eric Blake
2020-12-24 6:14 ` Vladimir Sementsov-Ogievskiy
2021-01-13 13:04 ` Markus Armbruster
2021-01-13 14:08 ` Eric Blake
2020-12-23 22:11 ` [PATCH v3 6/7] qapi: Use QAPI_LIST_APPEND in trivial cases Eric Blake
2020-12-24 9:56 ` Vladimir Sementsov-Ogievskiy
2021-01-13 14:10 ` Eric Blake
2021-01-13 13:16 ` Markus Armbruster
2021-01-13 14:11 ` Eric Blake
2020-12-23 22:11 ` [PATCH v3 7/7] qapi: More complex uses of QAPI_LIST_APPEND Eric Blake
2020-12-24 11:35 ` Vladimir Sementsov-Ogievskiy
2021-01-13 13:31 ` Markus Armbruster
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201223221102.390740-2-eblake@redhat.com \
--to=eblake@redhat.com \
--cc=armbru@redhat.com \
--cc=jasowang@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).