git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dmitry Potapov <dpotapov@gmail.com>
To: Joshua Juran <jjuran@gmail.com>
Cc: Giovanni Funchal <gafunchal@gmail.com>,
	git@vger.kernel.org, "Shawn O. Pearce" <spearce@spearce.org>,
	Johannes Sixt <j.sixt@viscovery.net>
Subject: [PATCH v2] correct verify_path for Windows
Date: Tue, 7 Oct 2008 07:26:23 +0400	[thread overview]
Message-ID: <20081007032623.GX21650@dpotapov.dyndns.org> (raw)
In-Reply-To: <B985AE98-F6E2-4C23-8D34-5A22A9F89FA7@gmail.com>

Colon and backslash in names may be used on Windows to overwrite files
outside of the working directory. Due to the file-system being case-
insensitive, .git can be written as any combination of upper and lower
characters, so we should check that too.

Signed-off-by: Dmitry Potapov <dpotapov@gmail.com>
---
In this version, I have added the check that files in .git/ will not
be overwritten by checkout. Overwriting such files as .git/config is
potentially exploitable.

Josh,

Does OS X need the same check below? I believe it has case-insensitive
filesystem, so it needs that too, but I am not sure what is the right
define should be used.

Thanks,
Dmitry

 read-cache.c |   19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/read-cache.c b/read-cache.c
index aff6390..7f855ee 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -668,10 +668,19 @@ static int verify_dotfile(const char *rest)
 	 * shares the path end test with the ".." case.
 	 */
 	case 'g':
+#if defined(_WIN32) || defined(__CYGWIN__)
+	/* On Windows, file names are case-insensitive */
+	case 'G':
+		if ((rest[1]|0x20) != 'i')
+			break;
+		if ((rest[2]|0x20) != 't')
+			break;
+#else
 		if (rest[1] != 'i')
 			break;
 		if (rest[2] != 't')
 			break;
+#endif
 		rest += 2;
 	/* fallthrough */
 	case '.':
@@ -703,6 +712,16 @@ inside:
 			}
 			return 0;
 		}
+#if defined(_WIN32) || defined(__CYGWIN__)
+		/*
+		 * There is a bunch of other characters that are not allowed
+		 * in Win32 API, but the following two create a security hole
+		 * by allowing to overwrite files outside of the working tree,
+		 * therefore they are explicitly prohibited.
+		 */
+		else if (c == ':' || c == '\\')
+			return 0;
+#endif
 		c = *path++;
 	}
 }
-- 
1.6.0

  reply	other threads:[~2008-10-07  3:32 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-02 14:02 Files with colons under Cygwin Giovanni Funchal
2008-10-04 23:39 ` Dmitry Potapov
2008-10-05  9:04   ` Alex Riesen
2008-10-05  9:14   ` Alex Riesen
2008-10-05 19:51     ` Dmitry Potapov
2008-10-05  9:28   ` Giovanni Funchal
2008-10-06  6:54   ` Johannes Sixt
2008-10-07  0:53     ` Dmitry Potapov
2008-10-07  6:13       ` Johannes Sixt
2008-10-07  2:05   ` Joshua Juran
2008-10-07  3:26     ` Dmitry Potapov [this message]
2008-10-07  6:18       ` [PATCH v2] correct verify_path for Windows Johannes Sixt
2008-10-11 16:33         ` Dmitry Potapov
2008-10-11 22:58           ` Alex Riesen
2008-10-12 13:50             ` Dmitry Potapov
2008-10-12 18:18               ` Alex Riesen
2008-10-13  6:00                 ` Johannes Sixt
2008-10-13  6:18                   ` Alex Riesen
2008-10-07  6:25       ` Alex Riesen

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=20081007032623.GX21650@dpotapov.dyndns.org \
    --to=dpotapov@gmail.com \
    --cc=gafunchal@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=j.sixt@viscovery.net \
    --cc=jjuran@gmail.com \
    --cc=spearce@spearce.org \
    /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).