From: John Crispin <john@phrozen.org>
To: Johannes Berg <johannes@sipsolutions.net>
Cc: linux-wireless@vger.kernel.org, John Crispin <john@phrozen.org>
Subject: [PATCH 6/7] iw: fix memory leaks inside handle_scan
Date: Fri, 17 May 2019 21:29:55 +0200 [thread overview]
Message-ID: <20190517192956.18372-7-john@phrozen.org> (raw)
In-Reply-To: <20190517192956.18372-1-john@phrozen.org>
Signed-off-by: John Crispin <john@phrozen.org>
---
scan.c | 31 +++++++++++++++----------------
1 file changed, 15 insertions(+), 16 deletions(-)
diff --git a/scan.c b/scan.c
index 980bfb4..6ad3ad4 100644
--- a/scan.c
+++ b/scan.c
@@ -389,7 +389,7 @@ static int handle_scan(struct nl80211_state *state,
bool passive = false, have_ssids = false, have_freqs = false;
bool duration_mandatory = false;
size_t ies_len = 0, meshid_len = 0;
- unsigned char *ies = NULL, *meshid = NULL, *tmpies;
+ unsigned char *ies = NULL, *meshid = NULL, *tmpies = NULL;
unsigned int flags = 0;
ssids = nlmsg_alloc();
@@ -450,7 +450,8 @@ static int handle_scan(struct nl80211_state *state,
case DONE:
nlmsg_free(ssids);
nlmsg_free(freqs);
- return 1;
+ err = 1;
+ goto nla_put_failure;
case FREQ:
freq = strtoul(argv[i], &eptr, 10);
if (eptr != argv[i] + strlen(argv[i])) {
@@ -462,6 +463,8 @@ static int handle_scan(struct nl80211_state *state,
NLA_PUT_U32(freqs, i, freq);
break;
case IES:
+ if (ies)
+ free(ies);
ies = parse_hex(argv[i], &ies_len);
if (!ies)
goto nla_put_failure;
@@ -490,24 +493,14 @@ static int handle_scan(struct nl80211_state *state,
if (ies || meshid) {
tmpies = (unsigned char *) malloc(ies_len + meshid_len);
- if (!tmpies) {
- free(ies);
- free(meshid);
+ if (!tmpies)
goto nla_put_failure;
- }
- if (ies) {
+ if (ies)
memcpy(tmpies, ies, ies_len);
- free(ies);
- }
- if (meshid) {
+ if (meshid)
memcpy(&tmpies[ies_len], meshid, meshid_len);
- free(meshid);
- }
- if (nla_put(msg, NL80211_ATTR_IE, ies_len + meshid_len, tmpies) < 0) {
- free(tmpies);
+ if (nla_put(msg, NL80211_ATTR_IE, ies_len + meshid_len, tmpies) < 0)
goto nla_put_failure;
- }
- free(tmpies);
}
if (!have_ssids)
@@ -535,6 +528,12 @@ static int handle_scan(struct nl80211_state *state,
nla_put_failure:
nlmsg_free(ssids);
nlmsg_free(freqs);
+ if (meshid)
+ free(meshid);
+ if (ies)
+ free(ies);
+ if (tmpies)
+ free(tmpies);
return err;
}
--
2.20.1
next prev parent reply other threads:[~2019-05-17 19:30 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-17 19:29 [PATCH 0/7] iw: various bug fixes John Crispin
2019-05-17 19:29 ` [PATCH 1/7] iw: fix memory leak inside register_mgmt_frame John Crispin
2019-05-17 19:29 ` [PATCH 2/7] iw: fix endless loop inside handle_mgmt_dump John Crispin
2019-05-17 19:29 ` [PATCH 3/7] iw: fix memory leak inside handle_cac John Crispin
2019-05-17 19:29 ` [PATCH 4/7] iw: fix fd leak inside handle_netns John Crispin
2019-05-17 19:29 ` [PATCH 5/7] iw: fix memory leak inside parse_sched_scan John Crispin
2019-05-17 19:29 ` John Crispin [this message]
2019-05-17 19:29 ` [PATCH 7/7] iw: fix fp handling inside handle_vendor John Crispin
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=20190517192956.18372-7-john@phrozen.org \
--to=john@phrozen.org \
--cc=johannes@sipsolutions.net \
--cc=linux-wireless@vger.kernel.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).