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: <20150206112429.6772a254@gandalf.local.home>
Date:	Fri, 6 Feb 2015 11:24:29 -0500
From:	Steven Rostedt <rostedt@...dmis.org>
To:	Al Viro <viro@...IV.linux.org.uk>
Cc:	linux-kernel@...r.kernel.org
Subject: Re: [RFC][PATCH v2 3/7] trace_events_filter.c: switch to memcmp()
 and memmem() for matching

On Fri,  6 Feb 2015 04:00:11 +0000
Al Viro <viro@...IV.linux.org.uk> wrote:

> From: Al Viro <viro@...iv.linux.org.uk>
> 
> we know the lengths in advance...
> 
> Signed-off-by: Al Viro <viro@...iv.linux.org.uk>
> ---
>  kernel/trace/trace_events_filter.c | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c
> index ced69da..6c4a96b 100644
> --- a/kernel/trace/trace_events_filter.c
> +++ b/kernel/trace/trace_events_filter.c
> @@ -271,21 +271,25 @@ static int filter_pred_none(struct filter_pred *pred, void *event)
>  
>  static int regex_match_full(char *str, struct regex *r, int len)
>  {
> -	if (strncmp(str, r->pattern, len) == 0)
> +	if (len - 1 != r->len)
> +		return 0;
> +	if (memcmp(str, r->pattern, r->len) == 0)
>  		return 1;
>  	return 0;
>  }
>  
>  static int regex_match_front(char *str, struct regex *r, int len)
>  {
> -	if (strncmp(str, r->pattern, r->len) == 0)
> +	if (len - 1 < r->len)
> +		return 0;
> +	if (memcmp(str, r->pattern, r->len) == 0)
>  		return 1;
>  	return 0;
>  }
>  
>  static int regex_match_middle(char *str, struct regex *r, int len)
>  {
> -	if (strnstr(str, r->pattern, len))
> +	if (memmem(str, len, r->pattern, r->len))

Since len includes '\0', shouldn't this be:

	if (memmem(str, len - 1, r->pattern, r->len);

It doesn't break the code either way, the algorithm still works, and
the original code did not pass in len-1 either. But if this is
optimizing the code, might as well eliminate one extra loop.

-- Steve

>  		return 1;
>  	return 0;
>  }

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ