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: <e23d695b-8cd1-9e22-af14-fe6fabb72efe@rasmusvillemoes.dk>
Date:   Sun, 28 Apr 2019 20:58:49 +0200
From:   Rasmus Villemoes <linux@...musvillemoes.dk>
To:     Yury Norov <yury.norov@...il.com>,
        Andrew Morton <akpm@...ux-foundation.org>,
        Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
        Dmitry Torokhov <dmitry.torokhov@...il.com>,
        "David S . Miller" <davem@...emloft.net>,
        Stephen Rothwell <sfr@...b.auug.org.au>,
        Amritha Nambiar <amritha.nambiar@...el.com>,
        Willem de Bruijn <willemb@...gle.com>,
        Kees Cook <keescook@...omium.org>,
        Matthew Wilcox <willy@...radead.org>,
        "Tobin C . Harding" <tobin@...nel.org>,
        Will Deacon <will.deacon@....com>,
        Miklos Szeredi <mszeredi@...hat.com>,
        Vineet Gupta <vineet.gupta1@...opsys.com>,
        Chris Wilson <chris@...is-wilson.co.uk>,
        Arnaldo Carvalho de Melo <acme@...hat.com>
Cc:     Yury Norov <ynorov@...vell.com>, linux-kernel@...r.kernel.org,
        Jens Axboe <axboe@...nel.dk>,
        Steffen Klassert <steffen.klassert@...unet.com>
Subject: Re: [PATCH 1/6] lib/string: add strnchrnul()

On 28/04/2019 05.29, Yury Norov wrote:
> New function works like strchrnul() with a length limited strings.
> 
> Signed-off-by: Yury Norov <ynorov@...vell.com>
> ---
>  include/linux/string.h |  3 +++
>  lib/string.c           | 20 ++++++++++++++++++++
>  2 files changed, 23 insertions(+)
> 
> diff --git a/include/linux/string.h b/include/linux/string.h
> index 4deb11f7976b..69e8df51b630 100644
> --- a/include/linux/string.h
> +++ b/include/linux/string.h
> @@ -62,6 +62,9 @@ extern char * strchr(const char *,int);
>  #ifndef __HAVE_ARCH_STRCHRNUL
>  extern char * strchrnul(const char *,int);
>  #endif
> +#ifndef __HAVE_ARCH_STRNCHRNUL

I find it unlikely this would ever be performance-critical, so an arch
would want to implement its own. Please let's avoid adding redundant
ifdeffery (and yes, there's probably quite a few of the existing ones
that should go away).

>  
> +#ifndef __HAVE_ARCH_STRNCHRNUL
> +/**
> + * strnchrnul - Find and return a character in a length limited string,
> + * or end of string
> + * @s: The string to be searched
> + * @count: The number of characters to be searched
> + * @c: The character to search for
> + *
> + * Returns pointer to first occurrence of 'c' in s. If c is not found,
> + * then return a pointer to the null byte at the end of s.

Pet peeve: nul, not null. Especially important when this is in contrast
to returning a NULL pointer. Also, the description is inaccurate; the
whole point of the n-variant is that there is not necessarily any nul
terminator.

> + */
> +char *strnchrnul(const char *s, int count, int c)
> +{

Yes, make count size_t so it's easier to distinguish from the c, and
keep this parameter ordering (that matches the str n chr name).

> +	while (count-- && *s && *s != (char)c)
> +		s++;
> +	return (char *)s;
> +}
> +EXPORT_SYMBOL(strnchrnul);

This can be added if a modular user shows up. No reason to add that
bloat to the kernel image immediately.

Rasmus

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ