Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2238204yba; Mon, 6 May 2019 02:16:06 -0700 (PDT) X-Google-Smtp-Source: APXvYqzUjmAnV2OeNWSTg9PBcJ6vf3/kRWzjjEv5NoRZ3kaVzw53xpMHy+kZnKHvStdZJSO69oei X-Received: by 2002:a17:902:4a0c:: with SMTP id w12mr31483099pld.52.1557134166269; Mon, 06 May 2019 02:16:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557134166; cv=none; d=google.com; s=arc-20160816; b=xdtNRUCkbgeufh8Fg3/Ge26l3eT7fkqhCQJACc2bHrfNDfDCCmkp4IYH/jMabMaqs3 AbZSfdIY+EsoJe11OUi76FSif8VYVWUex5dtQv65hs9B3RZ5FclEmVMArGseD1/bz11F +ldn01lYNp10hIyg+LZTEaVrF4muIoUBE43RTjC5ZpMwq+os7jb8ntxPD/shs41yD3EQ wWSG2uyYhOb+kr+Cli2Zydnu8LI14fhHxNYgIdaMZ/zDf/xom2aXBnuMEHCv+WZIuMaR TxUT3g0Isi+DEOz11OfiOHTO8+HwOWu2k3SqlLOyOtNLf7iSjwTPuX2E/B/zUSen+tyv umvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=06KAv0Gfe48A6SBZvN3UrZ6eJuwgu4hju0VN+FLCuQQ=; b=d7M1f6ZNv9x9GinP7A6QF48lyk0i60LPMONKkDrIr3S+UKgOEL6vgCPOhKs3W0ALJO hBA+A96khukbGajEOdiUNFCY3pVG3jFJeFziHRkqgf2VpiNrh+wDe5ZQJDBh0ZJHs29Q 9GdUkDKtBbP+mdGTZa3I1SMoOXLtw/dXWHyvrwRkMXqGZtwq09XWPYgVIkxLBEZ17elU 0qpKkvwR0rdRpW0KsJ5DQw8dJ7wDQ9ghw5hgYBBNmv+SwbtYBJcBMr7WcF25lhERRgRs pdui577/CWYNrAFIvDtFUx3HKVIVkA1yx+CAhQd0+ZYmXr2rzAuhzqFMVYSql/Ua9iWS sKsA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 m15si673437pfh.46.2019.05.06.02.15.50; Mon, 06 May 2019 02:16:06 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726399AbfEFJOr (ORCPT + 99 others); Mon, 6 May 2019 05:14:47 -0400 Received: from 0.ictbs.com ([203.137.112.168]:53975 "EHLO 0.ictbs.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725981AbfEFJOq (ORCPT ); Mon, 6 May 2019 05:14:46 -0400 Received: by hq.local (Postfix, from userid 1000) id 5596C66429; Mon, 6 May 2019 11:14:41 +0200 (CEST) Date: Mon, 6 May 2019 11:14:41 +0200 From: Victor Bravo <1905@spmblk.com> To: Kalle Valo 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 Message-ID: <20190506091441.wqtccm4n6xxhxom2@localhost> 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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87o94gug81.fsf@codeaurora.org> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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). Regards, v.