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

problem with backslash in directory name

From
JDJoachim Durchholz <jo@durchholz.org>
Date
Apr 7, 2017, 06:12 UTC
Message-ID
<9e3af7d6-a2c1-2673-53cc-d4c5105d9051@durchholz.org>
Hi all,

I'm having a problem with submodules that reside in directories that (unwisely) contain a backslash in their name.

Transcript:
### Arrange

$ git init main Initialized empty Git repository in /tmp/test/main/.git/

$ git init sub\\with\\backslash Initialized empty Git repository in /tmp/test/sub\with\backslash/.git/ # This looks okay: the shell interpreted \\ as \, # so we get sub\with\backslash

# Create a log entry in sub\with\backslash
# (it can't be added as a submodule otherwise)
# ((actually I think it's a misfeature, my current use case would be
# easier if git didn't insist on having a log in submodules))
$ touch sub\\with\\backslash/empty.file
$ git -C sub\\with\\backslash add empty.file
$ git -C sub\\with\\backslash commit -m "Added empty.file"
[master (root-commit) a27a485] Added empty.file
  1 file changed, 0 insertions(+), 0 deletions(-)
  create mode 100644 empty.file
### Act/Assert

$ git -C main submodule add ../sub\\with\\backslash fatal: repository '/tmp/test/sub\witackslash' does not exist fatal: clone of '/tmp/test/sub\witackslash' into submodule path 'sub\with\backslash' failed # The first "fatal:" line talks about "witackslash" # Um... "ackslash"? Now that's a nice nickname for a CVE :-)

# Okay, let's see what's actually in that message $ git -C main submodule add ../sub\\with\\backslash 2>&1 | xxd 00000000: 6661 7461 6c3a 2072 6570 6f73 6974 6f72 fatal: repositor 00000010: 7920 272f 746d 702f 7465 7374 2f73 7562 y '/tmp/test/sub 00000020: 5c77 6974 6808 6163 6b73 6c61 7368 2720 \with.ackslash' 00000030: 646f 6573 206e 6f74 2065 7869 7374 0a66 does not exist.f 00000040: 6174 616c 3a20 636c 6f6e 6520 6f66 2027 atal: clone of ' 00000050: 2f74 6d70 2f74 6573 742f 7375 625c 7769 /tmp/test/sub\wi 00000060: 7468 0861 636b 736c 6173 6827 2069 6e74 th.ackslash' int 00000070: 6f20 7375 626d 6f64 756c 6520 7061 7468 o submodule path 00000080: 2027 7375 625c 7769 7468 5c62 6163 6b73 'sub\with\backs 00000090: 6c61 7368 2720 6661 696c 6564 0a lash' failed.

# Yeah, there's a 0x08 at offset 0x25. # It's pretty strange that it is eliding the w following the \b, # not the h preceding it.

So... something inside "git submodule add" is replacing the \b with a backspace control code.

Next I tried something nasty:

$ mv sub\\with\\backslash 'sub: $(bc)' git -C main submodule add '../sub: $(bc)' Cloning into ' $(bc)'... done.

Whatever that "something" is, it is not doing shell expansion, otherwise it would have started an interactive calculator session. Phew :-) I'm still a bit uneasy because I don't know what other escape sequences might get interpreted, and what their effects are.

Next: Jeff King
Message 1 of 11 in “problem with backslash in directory name”
  1. Joachim DurchholzApr 7, 2017
  2. Jeff KingApr 7, 2017
  3. Joachim DurchholzApr 7, 2017
  4. Joachim DurchholzApr 7, 2017
  5. Brandon WilliamsApr 7, 2017
  6. Stefan BellerApr 7, 2017
  7. submodule: prevent backslash expantion in submodule namesBrandon Williams, Apr 7, 2017
  8. Joachim DurchholzApr 7, 2017
  9. Jeff KingApr 8, 2017
  10. Joachim DurchholzApr 8, 2017
  11. Junio C HamanoApr 17, 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.