All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Jim Meyering <jim@meyering.net>
Cc: git list <git@vger.kernel.org>,
	Brian Gernhardt <benji@silverinsanity.com>
Subject: Re: [PATCH] Fix off-by-one error: don't read the byte before a malloc'd buffer.
Date: Sun, 09 Dec 2007 10:15:34 -0800	[thread overview]
Message-ID: <7vsl2bpwe1.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: 87hcitgpca.fsf@rho.meyering.net

Jim Meyering <jim@meyering.net> writes:

> * config.c (store_write_pair): Don't read value[-1].
>
> Signed-off-by: Jim Meyering <meyering@redhat.com>
> ---
>  config.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/config.c b/config.c
> index ed96213..6031b38 100644
> --- a/config.c
> +++ b/config.c
> @@ -652,7 +652,7 @@ static int store_write_pair(int fd, const char* key, const char* value)
>  	for (i = 0; value[i]; i++)
>  		if (value[i] == ';' || value[i] == '#')
>  			quote = 1;
> -	if (value[i-1] == ' ')
> +	if (i && value[i-1] == ' ')
>  		quote = 1;
>
>  	if (write_in_full(fd, "\t", 1) != 1 ||

Thanks.

The fix may be correct but the comment above the part the patch fixes is
very misleading and I wasted a few minutes checking to see what it is
doing is correct.

The "quote" variable does not really control quoting; the quoting with
backslash is always done for the value, and this check is about adding a
dq pair around it, so that the parser does not lose leading or trailing
SP or string after start-of-comment marker characters.

  reply	other threads:[~2007-12-09 18:16 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-12-08 15:48 [PATCH] Fix off-by-one error: don't read the byte before a malloc'd buffer Jim Meyering
2007-12-09 18:15 ` Junio C Hamano [this message]
2007-12-09 19:24   ` Brian Gernhardt

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

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

  git send-email \
    --in-reply-to=7vsl2bpwe1.fsf@gitster.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=benji@silverinsanity.com \
    --cc=git@vger.kernel.org \
    --cc=jim@meyering.net \
    /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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.