Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2214665yba; Fri, 17 May 2019 12:37:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqw14ZcEUAjKzx+0VslQgs8DwVXawcjSeMrDOsI0gZGduCY73tTUad8bmXH4yMvqGYZTt830 X-Received: by 2002:a63:2b96:: with SMTP id r144mr44005280pgr.314.1558121830972; Fri, 17 May 2019 12:37:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558121830; cv=none; d=google.com; s=arc-20160816; b=hFm6uS5u7KFh7nJGYTMWrj5BS291ePsFBtQBDXm3B8xJUhotxLHrSFzsJBAoVKqzNb 8UbN+IVj8fEjAfgSXivDU/h8uDBzHWXCK0qDY+5Oh70CI8OE2hoK4hVoZCyxFwMgRev8 2lEpzsLusPVYs4BFNg9uevQqlphvG+X9ZgOEUWflUntYWu1nh4x5uZlNBeVKGvYIQawY xNqmDGwG7KIQCpIcGzn9+KpYJsPAQsyE6kn/b4rP6YnhEJ6m6MpTThKiYYIQ+K25a7z9 mHj2syVnoJMY7r9RebdbcZZZPNZpGzMEWXr6eFW78s6IcIZ4S9Vb6uCiwWSgPMvfqR/o Tm+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Wv3ELHquiPQCpOsx4nN3bfpDe0Sx4GhvcWLfD0VrxJw=; b=cPMYrmEFUndpKPnSizm1s0UxMlfR2U1P1C9Re4lMGXYx5KGh/Epnf2BZ+sUDPDella 5m+y7etelUsiE08EjJekUMeNZIWB5x4MecD2KL4/BrbzlkY6Rjc7U3CwTnJCZOt6RTmr 8woC1fH26klUIJklsq3PRHy1gVthP6PPWNYT5ofshKAglCENLboZL6Q3xiJ7z1ja/DXE NC31bI7gwYa/zYxOa7Pgxhq5VMvp9mrKLFXlw5+gV0opB/TEeispMuCnuMx2wqCap0kz Y8+4lQSVlWeuylmMww1m+RYwD0n1JyPqv84AV/ecfgPvPnmtLR0d65/PYFD+KsA3vbBA aIGw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t36si8618301pgl.371.2019.05.17.12.36.57; Fri, 17 May 2019 12:37:10 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729020AbfEQTaa (ORCPT + 99 others); Fri, 17 May 2019 15:30:30 -0400 Received: from nbd.name ([46.4.11.11]:37398 "EHLO nbd.name" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728951AbfEQTaa (ORCPT ); Fri, 17 May 2019 15:30:30 -0400 Received: from p548c8c9f.dip0.t-ipconnect.de ([84.140.140.159] helo=bertha.fritz.box) by ds12 with esmtpa (Exim 4.89) (envelope-from ) id 1hRiYm-0006cc-PZ; Fri, 17 May 2019 21:30:28 +0200 From: John Crispin To: Johannes Berg Cc: linux-wireless@vger.kernel.org, John Crispin Subject: [PATCH 6/7] iw: fix memory leaks inside handle_scan Date: Fri, 17 May 2019 21:29:55 +0200 Message-Id: <20190517192956.18372-7-john@phrozen.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190517192956.18372-1-john@phrozen.org> References: <20190517192956.18372-1-john@phrozen.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Signed-off-by: John Crispin --- 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