git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: "Ellié Computing Open Source Program" <opensource@elliecomputing.com>
Cc: Pierre Habouzit <madcoder@debian.org>,
	Junio C Hamano <gitster@pobox.com>,
	git@vger.kernel.org
Subject: Re: Problem listing GIT repository with accents
Date: Mon, 1 Feb 2010 06:32:13 -0500	[thread overview]
Message-ID: <20100201113213.GA22663@coredump.intra.peff.net> (raw)
In-Reply-To: <7E88665723814E46BCBA1A39E84C27A5@elrond>

On Mon, Feb 01, 2010 at 11:48:29AM +0100, Ellié Computing Open Source Program wrote:

> C:\temp\scc-tests\git>git ls-tree -r HEAD "caractère spécial"
> 100644 blob bf10a8b39e72c754ee1872fcdb13662cba6a8880    "caract\350re
> sp\351cial/\272plouf.txt"
> 
> Note the spurious \272 which comes in the listing :(
> Trying again the same commands may give other spurious characters
> (each time we tried we get different _bad_ responses)

Looks like a bug. I was able to replicate it here, and valgrind notices
it, too:

  ==22720== Invalid read of size 1
  ==22720==    at 0x80E77FF: next_quote_pos (quote.c:174)
  ==22720==    by 0x80E783A: quote_c_style_counted (quote.c:215)
  ==22720==    by 0x80E7D14: write_name_quotedpfx (quote.c:286)
  ==22720==    by 0x80808F3: show_tree (builtin-ls-tree.c:114)
  ==22720==    by 0x811000D: read_tree_recursive (tree.c:114)
  ==22720==    by 0x81100E7: read_tree_recursive (tree.c:131)
  ==22720==    by 0x8080CC2: cmd_ls_tree (builtin-ls-tree.c:173)
  ==22720==    by 0x804B7FA: run_builtin (git.c:257)
  ==22720==    by 0x804B958: handle_internal_command (git.c:412)
  ==22720==    by 0x804BA2F: run_argv (git.c:454)
  ==22720==    by 0x804BB97: main (git.c:525)
  ==22720==  Address 0x43405b4 is 0 bytes after a block of size 20 alloc'd
  ==22720==    at 0x4024C4C: malloc (vg_replace_malloc.c:195)
  ==22720==    by 0x8115739: xmalloc (wrapper.c:20)
  ==22720==    by 0x811005E: read_tree_recursive (tree.c:127)
  ==22720==    by 0x8080CC2: cmd_ls_tree (builtin-ls-tree.c:173)
  ==22720==    by 0x804B7FA: run_builtin (git.c:257)
  ==22720==    by 0x804B958: handle_internal_command (git.c:412)
  ==22720==    by 0x804BA2F: run_argv (git.c:454)
  ==22720==    by 0x804BB97: main (git.c:525)

The patch below fixes it for me. This is the first time I've ever looked
at this code, though, so an extra set of eyes is appreciated. I'm also
not sure of the "!p[len]" termination that the loop uses (quoted in the
context below). The string is explicitly not NUL-terminated, so why
would that matter? I think that may have been covering up the bug in
some cases.

-- >8 --
Subject: [PATCH] fix invalid read in quote_c_style_counted

We progress through a length-bounded string, looking for
characters in need of quoting. After each character is
found, we output everything up until that character
literally, then the quoted character. We then advance our
string and look again.  However, we never actually
decremented the length, meaning we ended up looking at
whatever random junk was stored after the string.

Signed-off-by: Jeff King <peff@peff.net>
---
 quote.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/quote.c b/quote.c
index acb6bf9..392006d 100644
--- a/quote.c
+++ b/quote.c
@@ -216,20 +216,21 @@ static size_t quote_c_style_counted(const char *name, ssize_t maxlen,
 		if (len == maxlen || !p[len])
 			break;
 
 		if (!no_dq && p == name)
 			EMIT('"');
 
 		EMITBUF(p, len);
 		EMIT('\\');
 		p += len;
 		ch = (unsigned char)*p++;
+		maxlen -= len + 1;
 		if (sq_lookup[ch] >= ' ') {
 			EMIT(sq_lookup[ch]);
 		} else {
 			EMIT(((ch >> 6) & 03) + '0');
 			EMIT(((ch >> 3) & 07) + '0');
 			EMIT(((ch >> 0) & 07) + '0');
 		}
 	}
 
 	EMITBUF(p, len);
-- 
1.7.0.rc1.16.g21332.dirty

  reply	other threads:[~2010-02-01 11:32 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-01 10:48 Problem listing GIT repository with accents Ellié Computing Open Source Program
2010-02-01 11:32 ` Jeff King [this message]
2010-02-01 12:19   ` Jeff King
2010-02-01 12:48     ` Johannes Sixt
2010-02-01 13:39       ` Jeff King
2010-02-01 13:44         ` Jeff King
2010-02-01 17:21           ` Junio C Hamano
2010-02-01 17:40             ` Jeff King

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=20100201113213.GA22663@coredump.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=madcoder@debian.org \
    --cc=opensource@elliecomputing.com \
    /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 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 NNTP newsgroup(s).