lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20181223175621.4e4d958c@vmware.local.home>
Date:   Sun, 23 Dec 2018 17:56:21 -0500
From:   Steven Rostedt <rostedt@...dmis.org>
To:     Rasmus Villemoes <linux@...musvillemoes.dk>
Cc:     Joe Perches <joe@...ches.com>,
        Andreas Schwab <schwab@...ux-m68k.org>,
        Linus Torvalds <torvalds@...ux-foundation.org>,
        Linux List Kernel Mailing <linux-kernel@...r.kernel.org>,
        Ingo Molnar <mingo@...nel.org>,
        Andrew Morton <akpm@...ux-foundation.org>,
        Namhyung Kim <namhyung@...nel.org>,
        Masami Hiramatsu <mhiramat@...nel.org>,
        Tom Zanussi <zanussi@...nel.org>,
        Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Subject: Re: [for-next][PATCH 23/24] string.h: Add strncmp_prefix() helper
 macro

On Sun, 23 Dec 2018 23:01:52 +0100
Rasmus Villemoes <linux@...musvillemoes.dk> wrote:

> On 21/12/2018 23.20, Joe Perches wrote:
> > On Fri, 2018-12-21 at 16:08 -0500, Steven Rostedt wrote:  
> >> On Fri, 21 Dec 2018 21:58:32 +0100
> >> Andreas Schwab <schwab@...ux-m68k.org> wrote:
> >>
> >>  
> >>>> Well, perhaps I can just remove the ending ones. I get paranoid with
> >>>> macro variables, and tend to over do it so that there's no question.    
> >>>
> >>> Why not make it an inline function?  
> >>
> >> Matters if that removes the strlen(const) optimization. I could try it
> >> and see what happens.  
> > 
> > Using
> > 
> > static inline bool str_has_prefix(const char *str, const char prefix[])
> > {
> > 	return !strncmp(str, prefix, strlen(prefix));
> > }
> >   
> 
> We already have exactly that function, it's called strstarts().

It's not exact.

> 
> commit 66f92cf9d415e96a5bdd6c64de8dd8418595d2fc
> Author: Rusty Russell <rusty@...tcorp.com.au>
> Date:   Tue Mar 31 13:05:36 2009 -0600
> 
>     strstarts: helper function for !strncmp(str, prefix, strlen(prefix))
> 
> Please don't add a copy under another name.
> 
> As for converting existing users, go for it. FWIW, I ran a cocci script
> a few years ago to find suspicious strncmp() cases, and there were some
> (e87c3f, ca957b6), but fewer than I expected. There are some
> confused/confusing ones that apparently deliberately do strncmp(a, b,
> sizeof(b)) instead of the equivalent to strcmp(a, b) (e.g. 'strncmp(str,
> "hwc", 4) == 0')

Well, one thing that str_has_prefix() does that strstarts() does not,
is to return the prefix length which gets rid of the duplication.

Would it be OK to convert strstarts() to return the length of prefix?

-- Steve

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ