git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "René Scharfe" <l.s.r@web.de>
Cc: Git Mailing List <git@vger.kernel.org>
Subject: Re: [PATCH] diff: parse ws-error-highlight option more strictly
Date: Sun, 12 Jul 2015 09:55:17 -0700	[thread overview]
Message-ID: <xmqq4ml9joy2.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <55A112ED.3090004@web.de> ("René Scharfe"'s message of "Sat, 11 Jul 2015 14:58:21 +0200")

René Scharfe <l.s.r@web.de> writes:

> Check if a matched token is followed by a delimiter before advancing the
> pointer arg.  This avoids accepting composite words like "allnew" or
> "defaultcontext".
>
> Signed-off-by: Rene Scharfe <l.s.r@web.de>
> ---
>  diff.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/diff.c b/diff.c
> index 87b16d5..0f17ec5 100644
> --- a/diff.c
> +++ b/diff.c
> @@ -3653,7 +3653,12 @@ static void enable_patch_output(int *fmt) {
>  
>  static int parse_one_token(const char **arg, const char *token)
>  {
> -	return skip_prefix(*arg, token, arg) && (!**arg || **arg == ',');
> +	const char *rest;
> +	if (skip_prefix(*arg, token, &rest) && (!*rest || *rest == ',')) {
> +		*arg = rest;
> +		return 1;
> +	}
> +	return 0;
>  }

So the bug is, when fed "allnew", calls to this function are done
with "none" and "default" (both of which fail skip_prefix()), then
with "all", at which point skip_prefix() advance the *arg pointer to
"allnew"+3 (i.e. pointing at 'n') and the check on the "are we at
the end of token?" fails. The next call is for "new" and it
incorrectly passes.

Thanks for spotting.

An unrelated tangent, but I misnamed this function grossly, it
seems.  Even if this is a file-scope static, it is selfish to claim
that this function is the only one that will ever parse any kind of
token in this file.  As this is a helper that can be used to parse
any string with comma-separated tokens, I should have named it with
some word that hints that fact.

      reply	other threads:[~2015-07-12 16:55 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-11 12:58 [PATCH] diff: parse ws-error-highlight option more strictly René Scharfe
2015-07-12 16:55 ` Junio C Hamano [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqq4ml9joy2.fsf@gitster.dls.corp.google.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=l.s.r@web.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).