From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.7 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 21FEDC04A6B for ; Mon, 6 May 2019 12:29:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E7CD7206A3 for ; Mon, 6 May 2019 12:29:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="key not found in DNS" (0-bit key) header.d=codeaurora.org header.i=@codeaurora.org header.b="gKs7elg/"; dkim=fail reason="key not found in DNS" (0-bit key) header.d=codeaurora.org header.i=@codeaurora.org header.b="Zo1+MTb4" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726324AbfEFM32 (ORCPT ); Mon, 6 May 2019 08:29:28 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:58148 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726302AbfEFM31 (ORCPT ); Mon, 6 May 2019 08:29:27 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id C7CFC60AA8; Mon, 6 May 2019 12:29:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1557145766; bh=VCvP/gZAtcdtOifWNcdeLJAMQjdxY3mj3YVbMsOAGFI=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=gKs7elg/jakUd1+If6pY68R2V2fGRDiDkVZnz7fRxK+hiBdNjaMGjyvIp9KnI/hKJ z9MXEHrPirmW10V6rW3x+jEr4zKke9MZjCvwZQElbkqUqA3xyppoSvil+P268o2Az+ nEabs75gO9UfpmaqXTCWcB1NUqULdTYT4upQvfMM= Received: from x230.qca.qualcomm.com (85-76-75-57-nat.elisa-mobile.fi [85.76.75.57]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: kvalo@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 3B5676063F; Mon, 6 May 2019 12:29:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1557145765; bh=VCvP/gZAtcdtOifWNcdeLJAMQjdxY3mj3YVbMsOAGFI=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=Zo1+MTb4vOE/Wr9aNHItSl0CLGLIok2gBzecwaLxeD8j8IWrtk6cFTxoD9gQAm3ba QnY+juX0Pt4luoptzPeLC1F7toNvNAyoxOvcZYuPu7QXLhFAgqD33zvdTCGViokt8z NB8LqrF5CcuTf+FE1mYYRY4nUWRVWnjzmgEVHsQk= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 3B5676063F Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=kvalo@codeaurora.org From: Kalle Valo To: Victor Bravo <1905@spmblk.com> Cc: Hans de Goede , Arend Van Spriel , Franky Lin , Hante Meuleman , Chi-Hsien Lin , Wright Feng , "David S. Miller" , linux-wireless@vger.kernel.org, brcm80211-dev-list.pdl@broadcom.com, brcm80211-dev-list@cypress.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH RFC] brcmfmac: sanitize DMI strings v2 References: <20190504162633.ldrz2nqfocg55grb@localhost> <20190504194440.4zcxjrtj2aft3ka4@localhost> <16a87149068.2764.9b12b7fc0a3841636cfb5e919b41b954@broadcom.com> <20190505150355.3fbng4ny34x255vk@localhost> <0f75a3d4-94af-5503-94c3-e8af2364448d@redhat.com> <87o94gug81.fsf@codeaurora.org> <20190506091441.wqtccm4n6xxhxom2@localhost> Date: Mon, 06 May 2019 15:29:21 +0300 In-Reply-To: <20190506091441.wqtccm4n6xxhxom2@localhost> (Victor Bravo's message of "Mon, 6 May 2019 11:14:41 +0200") Message-ID: <878svjvk9q.fsf@codeaurora.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Victor Bravo <1905@spmblk.com> writes: > On Mon, May 06, 2019 at 11:42:06AM +0300, Kalle Valo wrote: >> Hans de Goede writes: >> >> >> @@ -99,6 +107,15 @@ static const struct dmi_system_id dmi_platform_data[] = { >> >> {} >> >> }; >> >> +void brcmf_dmi_sanitize(char *dst, const unsigned char *allowed, >> >> char safe) >> >> +{ >> >> + while (*dst) { >> >> + if ((*dst < 0) || !(allowed[*dst / 8] & (1 << (*dst % 8)))) >> > >> > At a first look I have no clue what this code is doing and I honestly do not feel >> > like figuring it out, this is clever, but IMHO not readable. >> > >> > Please just write this as if (*dst < 0x21 || (*dst > foo && < bar) || etc, >> > so that a human can actually see in one look what the code is doing. >> >> Is there an existing function for sanitising filenames so that we don't >> need to reinvent the wheel, maybe something like isalnum()? > > I would definitely prefer to use existing function, but I didn't find > any suitable one. Suggestions are welcome. I didn't find anything either, but hopefully someone knows. > As for implementation details, the one I posted was optimized for both > speed and size, and at least in my opinion this bit array driven > parametric implementation is exactly what is needed here (using a string > of allowed characters with strchr-style lookups would bring much worse > complexity, and checking the characters using series of hardcoded if > conditions could quickly grow to more than those 16 bytes used by the > array). But is this really something which should be optimised? This is driver initialisation, not in some hot path, right? Can you even measure the difference? -- Kalle Valo