From patchwork Wed Aug 22 13:22:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 10572951 X-Patchwork-Delegate: kvalo@adurom.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 678FC920 for ; Wed, 22 Aug 2018 13:22:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 57F532B448 for ; Wed, 22 Aug 2018 13:22:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4C7AA2B40A; Wed, 22 Aug 2018 13:22:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DDAD12B3B4 for ; Wed, 22 Aug 2018 13:22:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729085AbeHVQrV (ORCPT ); Wed, 22 Aug 2018 12:47:21 -0400 Received: from mail-lf1-f68.google.com ([209.85.167.68]:46700 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728057AbeHVQrU (ORCPT ); Wed, 22 Aug 2018 12:47:20 -0400 Received: by mail-lf1-f68.google.com with SMTP id e23-v6so1354562lfc.13 for ; Wed, 22 Aug 2018 06:22:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=from:to:cc:subject:date:message-id; bh=AZbPCJSbuo+klDBiBLb68ajVcTgBIaGryLAqoz1zbFg=; b=c1XxSt2o2MKrhLyRBXaEtIfAcbI419co9oJDsRtm/1ugtcaVk1NmSKqrTq1jUJjn1h 8miGzVkWXgpsmSKqx7XshYhc/cCao2Qb0Sm6qaG/YjOhJGRHCdp3jKv4Wu/GbwST7OAE Ko5WAhrifPAUcuB7fvHb/Rwa6lxNT5BUQyC+I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=AZbPCJSbuo+klDBiBLb68ajVcTgBIaGryLAqoz1zbFg=; b=fHahpnv0aZ8R72LwFkXHKyTbeoOTbHQBRdv0GfYkwewAnHocO3CQM5X7TpL9SGT0RR s5gl+s2xE5t2eWSMfkNMmio0hBtpbhZm2A0QrYNgMKKrD/R+lNpIsaBL47y299XZkKer 2n0pK2POveWDxPsWUBfGSMVv9jjF8usIk6DuBrEmZIDcF2V7oBkw/GdBq+LvAESTGyR8 J/Sw14AREZDLbDzyvNWjiho6UVzylHSWB1gTZswd62z+ksj2w8JLl81OHiYhgGQO/rgj JA5HFdgQqWPi+AtaKjLNvkYygPzmvcIrjnT3ihv+316HVUbYR/6qM01Y0Y04exLv+feE zDAA== X-Gm-Message-State: APzg51AZN7rf/QicG7Dhe++3yaXGseBUNfHPD6I0WRp90J5EyDTDWrAN nPImluqfkYX6A2AulEfMyfNDRw== X-Google-Smtp-Source: ANB0VdZ3jPavtSuzCCpfqzFJ8USRyKgm/35Ri6ufCmVAlYn9DU87oCfj5otS4UyDdVAh1YM1XF0P+Q== X-Received: by 2002:a19:e593:: with SMTP id i19-v6mr654385lfk.18.1534944144439; Wed, 22 Aug 2018 06:22:24 -0700 (PDT) Received: from prevas-ravi.prevas.se ([81.216.59.226]) by smtp.gmail.com with ESMTPSA id i2-v6sm314600lfa.78.2018.08.22.06.22.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 22 Aug 2018 06:22:24 -0700 (PDT) From: Rasmus Villemoes To: Kalle Valo , "David S. Miller" Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-wireless@vger.kernel.org, Rasmus Villemoes Subject: [PATCH] brcmfmac: fix wrong strnchr usage Date: Wed, 22 Aug 2018 15:22:15 +0200 Message-Id: <20180822132215.27669-1-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.16.4 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP strnchr takes arguments in the order of its name: string, max bytes to read, character to search for. Here we're passing '\n' aka 10 as the buffer size, and searching for sizeof(buf) aka BRCMF_DCMD_SMLEN aka 256 (aka '\0', since it's implicitly converted to char) within those 10 bytes. Just interchanging the last two arguments would still leave a bug, because if we've been successful once, there are not sizeof(buf) characters left after the new value of p. Since clmver is immediately afterwards passed as a %s argument, I assume that it is actually a properly nul-terminated string. For that case, we have strreplace(). Signed-off-by: Rasmus Villemoes --- Incidentally, I found this because I was looking at our strnchr implementation and noticed a corner case: strchr() is specified by C and POSIX standards to consider the trailing '\0' to be part of the string, so strchr(foo, '\0') must be equivalent to "foo + strlen(foo)". strnchr() is not specified by anyone. Our implementation returns NULL as soon as count is depleted or hitting a '\0' byte, so since we were here looking for a '\0' byte, the first strnchr() call was guaranteed to return NULL. Had strnchr() instead returned a pointer to the '\0' if such was found within the first count (in this case 10) bytes, we'd be overwriting that with a ' ', and continue until no '\0' was found within the next 10 bytes. drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c index cd3651069d0c..94044a7a6021 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c @@ -296,9 +296,7 @@ int brcmf_c_preinit_dcmds(struct brcmf_if *ifp) /* Replace all newline/linefeed characters with space * character */ - ptr = clmver; - while ((ptr = strnchr(ptr, '\n', sizeof(buf))) != NULL) - *ptr = ' '; + strreplace(clmver, '\n', ' '); brcmf_dbg(INFO, "CLM version = %s\n", clmver); }