From patchwork Fri Feb 8 16:57:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Berg X-Patchwork-Id: 1038852 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=hostap-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=sipsolutions.net Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="hXfnEQ7w"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43x2ks4hFnz9sMr for ; Sat, 9 Feb 2019 04:49:57 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=LRVcUmu7+3P/En02NoHLDtFgrXbunwr36KDoNKCY5vI=; b=hXfnEQ7waxWSJIn8WMLXNd8aa6 +yCrXOBrqYfLfXvkpufJkKbi3OpltPrD97eO+8MAm34w/qCVDFoTkuHfa3+RTif85ud99G1oKGuD5 tLysBv0sefnspFX1DnVx7qBmeGJqJzvGFVqxk/+yIDsrJzRhfHc0VnWfiABZcX5yFANK822npSNBm m9MkIN8ppYF0t1RaBN1Y15TL0eiuhfxo2e6X3RCtZL5RPFsyUg8Q6zizAU8zwBz2Ls6UjcQ1NbymR HdmvYQOrtwjzcPTGC21fbzKB0CCubkGfzPC8UFe3v9Gnu4pvlf3+3i0y8koQjKg+ZtgwGgK3ExTKn Q0WCNLvg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gsAHa-0001vz-Lw; Fri, 08 Feb 2019 17:49:46 +0000 Received: from s3.sipsolutions.net ([2a01:4f8:191:4433::2] helo=sipsolutions.net) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gsAGy-0001BR-QJ for hostap@lists.infradead.org; Fri, 08 Feb 2019 17:49:12 +0000 Received: by sipsolutions.net with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92-RC4) (envelope-from ) id 1gsAGv-0006Ro-DZ; Fri, 08 Feb 2019 18:49:05 +0100 From: Johannes Berg To: hostap@lists.infradead.org Subject: [PATCH 4/5] common: use for_each_element_id() in mb_ies_info_by_ies() Date: Fri, 8 Feb 2019 17:57:51 +0100 Message-Id: <20190208165752.24698-4-johannes@sipsolutions.net> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190208165752.24698-1-johannes@sipsolutions.net> References: <20190208165752.24698-1-johannes@sipsolutions.net> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190208_094908_863888_415CA502 X-CRM114-Status: GOOD ( 11.39 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- X-BeenThere: hostap@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Johannes Berg MIME-Version: 1.0 Sender: "Hostap" Errors-To: hostap-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Johannes Berg The change is bigger because here we need to catch the error condition if the last element doesn't fit. Signed-off-by: Johannes Berg --- src/common/ieee802_11_common.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/src/common/ieee802_11_common.c b/src/common/ieee802_11_common.c index e103551e779e..1b80e13aa649 100644 --- a/src/common/ieee802_11_common.c +++ b/src/common/ieee802_11_common.c @@ -1323,27 +1323,25 @@ const char * fc2str(u16 fc) int mb_ies_info_by_ies(struct mb_ies_info *info, const u8 *ies_buf, size_t ies_len) { - os_memset(info, 0, sizeof(*info)); + struct element *elem; - while (ies_buf && ies_len >= 2 && - info->nof_ies < MAX_NOF_MB_IES_SUPPORTED) { - size_t len = 2 + ies_buf[1]; + os_memset(info, 0, sizeof(*info)); - if (len > ies_len) { - wpa_hexdump(MSG_DEBUG, "Truncated IEs", - ies_buf, ies_len); - return -1; - } + for_each_element_id(elem, WLAN_EID_MULTI_BAND, ies_buf, ies_len) { + if (info->nof_ies >= MAX_NOF_MB_IES_SUPPORTED) + break; - if (ies_buf[0] == WLAN_EID_MULTI_BAND) { - wpa_printf(MSG_DEBUG, "MB IE of %zu bytes found", len); - info->ies[info->nof_ies].ie = ies_buf + 2; - info->ies[info->nof_ies].ie_len = ies_buf[1]; - info->nof_ies++; - } + wpa_printf(MSG_DEBUG, "MB IE of %u bytes found", + (unsigned int)elem->datalen + 2); + info->ies[info->nof_ies].ie = elem->data; + info->ies[info->nof_ies].ie_len = elem->datalen; + info->nof_ies++; + } - ies_len -= len; - ies_buf += len; + if (!for_each_element_completed(elem, ies_buf, ies_len)) { + wpa_hexdump(MSG_DEBUG, "Truncated IEs", + elem, ies_buf + ies_len - (const u8 *)elem); + return -1; } return 0;