git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 2/2] test-lib: exhaustively insert non-alnum ASCII into the TRASH_DIRECTORY name

From
Jeff King <peff@peff.net>
Date
Apr 11, 2017, 01:14 UTC
Message-ID
<20170411011454.oteysryg4t44gebj@sigill.intra.peff.net>
In-Reply-To
<CACBZZX7OfM-zivJAQMXdNarHDjAhzQhqGNZNs2QqDUyOo3AA0g@mail.gmail.com>
On Tue, Apr 11, 2017 at 01:23:32AM +0200, Ævar Arnfjörð Bjarmason wrote:
Show 17 quoted lines
> * Most of the tests fail because git clone can't deal with cloning a
> repo with a \r in the path. The error we produce when we try is quite
> bad and doesn't indicate what went wrong:
> 
> $ rm -rf /tmp/git.*; mkdir /tmp/git.$(perl -e 'print chr 13') && cd
> /tmp/git.* && git init --bare b && file b && git clone b c
> /b/tialized empty Git repository in /tmp/git.
> b: directory
> Cloning into 'c'...
> fatal: '/tmp/git. /b' does not appear to be a git repository
> fatal: Could not read from remote repository.
> 
> Please make sure you have the correct access rights
> and the repository exists.
> 
> So file(1) shows it exists, a strace shows that git knows it exists at
> some point, but something gets lost along the way.
It's the round-trip through the config. It writes:
  [remote "origin"]
  url = /tmp/git.^M/b

into the config (where ^M is a literal CR). And then on reading it back, unquoted whitespace in config values is converted to spaces, which is why you see "git. /b" in the error message (the other ones are ugly because it's writing the raw CR in via printf, and your terminal respects it. Try "2>&1 | cat -A" when debugging this sort of thing (our error and warning messages clean up cruft like this already, but informational messages don't always go through vreportf()).

Anyway, something like this would fix it (it actually adds "\r" to the config format, which is how we handle \n and \t; we could do it without touching the parsing side if we taught store_write_pair() to recognize that \r needs to go in double-quotes).

diff --git a/config.c b/config.c
index 1a4d85537..4a36a37ba 100644
--- a/config.c
+++ b/config.c
@@ -526,6 +526,9 @@ static char *parse_value(void)
 			case 'n':
 				c = '\n';
 				break;
+			case 'r':
+				c = '\r';
+				break;
 			/* Some characters escape as themselves */
 			case '\\': case '"':
 				break;
@@ -2172,6 +2175,9 @@ static int store_write_pair(int fd, const char *key, const char *value)
 		case '\t':
 			strbuf_addstr(&sb, "\\t");
 			break;
+		case '\r':
+			strbuf_addstr(&sb, "\\r");
+			break;
 		case '"':
 		case '\\':
 			strbuf_addch(&sb, '\\');

-Peff
Previous: Ævar Arnfjörð BjarmasonNext: Joachim Durchholz
Message 23 of 25 in “test: Detect *lots* of bugs by adding non-alnum to trash dir names”
  1. 0/2 test: Detect *lots* of bugs by adding non-alnum to trash dir namesÆvar Arnfjörð Bjarmason, Apr 9, 2017
  2. 1/2 tests: mark tests that fail when the TEST_DIRECTORY is unusualÆvar Arnfjörð Bjarmason, Apr 9, 2017
  3. 2/2 test-lib: exhaustively insert non-alnum ASCII into the TRASH_DIRECTORY nameÆvar Arnfjörð Bjarmason, Apr 9, 2017
  4. SZEDER GáborApr 10, 2017
  5. Ævar Arnfjörð BjarmasonApr 10, 2017
  6. SZEDER GáborApr 10, 2017
  7. Ævar Arnfjörð BjarmasonApr 10, 2017
  8. Jeff KingApr 10, 2017
  9. Joachim DurchholzApr 10, 2017
  10. Jeff KingApr 10, 2017
  11. Joachim DurchholzApr 10, 2017
  12. Jeff KingApr 10, 2017
  13. SZEDER GáborApr 10, 2017
  14. Ævar Arnfjörð BjarmasonApr 10, 2017
  15. connect.c: handle errors from split_cmdlineJeff King, Apr 11, 2017
  16. Jeff KingApr 11, 2017
  17. Ævar Arnfjörð BjarmasonApr 11, 2017
  18. Jeff KingApr 11, 2017
  19. Ævar Arnfjörð BjarmasonApr 11, 2017
  20. Junio C HamanoApr 17, 2017
  21. Junio C HamanoApr 17, 2017
  22. Ævar Arnfjörð BjarmasonApr 19, 2017
  23. Jeff KingApr 11, 2017
  24. Joachim DurchholzApr 11, 2017
  25. Joachim DurchholzApr 9, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.