[PATCH 11/40] Windows: Handle absolute paths in safe_create_leading_directories().

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Johannes Sixt
Date: Wednesday, February 27, 2008 - 11:54 am

In this function we must be careful to handle drive-local paths else there
is a danger that it runs into an infinite loop.

Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
---
 sha1_file.c |   14 ++++++++++----
 1 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/sha1_file.c b/sha1_file.c
index 453bc43..0c60849 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -83,14 +83,20 @@ int get_sha1_hex(const char *hex, unsigned char *sha1)
 	return 0;
 }
 
+static inline int offset_1st_component(const char *path)
+{
+#ifdef __MINGW32__
+	if (isalpha(path[0]) && path[1] == ':')
+		return 2 + (path[2] == '/');
+#endif
+	return *path == '/';
+}
+
 int safe_create_leading_directories(char *path)
 {
-	char *pos = path;
+	char *pos = path + offset_1st_component(path);
 	struct stat st;
 
-	if (is_absolute_path(path))
-		pos++;
-
 	while (pos) {
 		pos = strchr(pos, '/');
 		if (!pos)
-- 
1.5.4.1.126.ge5a7d

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 00/40] MinGW port, Johannes Sixt, (Wed Feb 27, 11:54 am)
[PATCH 02/40] Compile some programs only conditionally., Johannes Sixt, (Wed Feb 27, 11:54 am)
[PATCH 03/40] Add target architecture MinGW., Johannes Sixt, (Wed Feb 27, 11:54 am)
[PATCH 09/40] Windows: Work around misbehaved rename()., Johannes Sixt, (Wed Feb 27, 11:54 am)
[PATCH 10/40] Windows: Treat Windows style path names., Johannes Sixt, (Wed Feb 27, 11:54 am)
[PATCH 11/40] Windows: Handle absolute paths in safe_creat ..., Johannes Sixt, (Wed Feb 27, 11:54 am)
[PATCH 12/40] Windows: Implement gettimeofday()., Johannes Sixt, (Wed Feb 27, 11:54 am)
[PATCH 13/40] Windows: Fix PRIuMAX definition., Johannes Sixt, (Wed Feb 27, 11:54 am)
[PATCH 18/40] Windows: Implement start_command()., Johannes Sixt, (Wed Feb 27, 11:54 am)
[PATCH 20/40] Windows: A rudimentary poll() emulation., Johannes Sixt, (Wed Feb 27, 11:54 am)
[PATCH 27/40] Windows: Implement a custom spawnve()., Johannes Sixt, (Wed Feb 27, 11:54 am)
[PATCH 30/40] Turn builtin_exec_path into a function., Johannes Sixt, (Wed Feb 27, 11:54 am)
[PATCH 34/40] Windows: Make the pager work., Johannes Sixt, (Wed Feb 27, 11:54 am)
[PATCH 37/40] Windows: Make 'git help -a' work., Johannes Sixt, (Wed Feb 27, 11:55 am)
Re: [PATCH 00/40] MinGW port, Marius Storm-Olsen, (Wed Feb 27, 3:01 pm)
Re: [PATCH 00/40] MinGW port, Martin Langhoff, (Wed Feb 27, 4:34 pm)
Re: [PATCH 01/40] Add compat/regex.[ch] and compat/fnmatch ..., Johannes Schindelin, (Wed Feb 27, 4:43 pm)
Re: [PATCH 00/40] MinGW port, Johannes Schindelin, (Wed Feb 27, 4:58 pm)
Re: [PATCH 00/40] MinGW port, Nguyen Thai Ngoc Duy, (Wed Feb 27, 8:38 pm)
Re: [PATCH 37/40] Windows: Make 'git help -a' work., Paolo Bonzini, (Thu Feb 28, 2:52 am)
Re: [PATCH 02/40] Compile some programs only conditionally., Johannes Schindelin, (Thu Feb 28, 4:57 am)
Re: [PATCH 03/40] Add target architecture MinGW., Johannes Schindelin, (Thu Feb 28, 5:05 am)
Re: [PATCH 08/40] Windows: always chmod(, 0666) before unl ..., Johannes Schindelin, (Thu Feb 28, 5:09 am)
Re: [PATCH 10/40] Windows: Treat Windows style path names., Johannes Schindelin, (Thu Feb 28, 5:18 am)
Re: [PATCH 13/40] Windows: Fix PRIuMAX definition., Johannes Schindelin, (Thu Feb 28, 5:21 am)
Re: [PATCH 03/40] Add target architecture MinGW., Paolo Bonzini, (Thu Feb 28, 5:57 am)
Re: [PATCH 03/40] Add target architecture MinGW., Johannes Schindelin, (Thu Feb 28, 7:56 am)
Re: [PATCH 19/40] Windows: Change the name of hook scripts ..., Johannes Schindelin, (Thu Feb 28, 8:20 am)
Re: [PATCH 21/40] Windows: Disambiguate DOS style paths fr ..., Johannes Schindelin, (Thu Feb 28, 8:22 am)
Re: [PATCH 22/40] Windows: Implement asynchronous function ..., Johannes Schindelin, (Thu Feb 28, 8:28 am)
Re: [PATCH 23/40] Windows: Local clone must use the drive ..., Johannes Schindelin, (Thu Feb 28, 8:31 am)
Re: [PATCH 27/40] Windows: Implement a custom spawnve()., Johannes Schindelin, (Thu Feb 28, 8:36 am)
Re: [PATCH 33/40] When installing, be prepared that templa ..., Johannes Schindelin, (Thu Feb 28, 8:45 am)
Re: [PATCH 40/40] compat/pread.c: Add foward decl to fix w ..., Johannes Schindelin, (Thu Feb 28, 8:51 am)
Re: [PATCH 03/40] Add target architecture MinGW., Johannes Sixt, (Thu Feb 28, 1:40 pm)
Re: [PATCH 13/40] Windows: Fix PRIuMAX definition., Johannes Sixt, (Thu Feb 28, 1:45 pm)
Re: [PATCH 27/40] Windows: Implement a custom spawnve()., Johannes Sixt, (Thu Feb 28, 2:04 pm)
Re: [PATCH 02/40] Compile some programs only conditionally., Johannes Schindelin, (Thu Feb 28, 5:47 pm)
Re: [PATCH 03/40] Add target architecture MinGW., Johannes Schindelin, (Thu Feb 28, 6:07 pm)
Re: [PATCH 04/40] Windows: Use the Windows style PATH sepa ..., Johannes Schindelin, (Thu Feb 28, 6:09 pm)
Re: [PATCH 19/40] Windows: Change the name of hook scripts ..., Johannes Schindelin, (Thu Feb 28, 6:11 pm)
Re: [PATCH 22/40] Windows: Implement asynchronous function ..., Johannes Schindelin, (Thu Feb 28, 6:17 pm)
Re: [PATCH 27/40] Windows: Implement a custom spawnve()., Johannes Schindelin, (Thu Feb 28, 6:18 pm)
Re: [PATCH 33/40] When installing, be prepared that templa ..., Johannes Schindelin, (Thu Feb 28, 6:21 pm)
Re: [PATCH 22/40] Windows: Implement asynchronous function ..., Johannes Schindelin, (Thu Feb 28, 6:27 pm)
Re: [PATCH 22/40] Windows: Implement asynchronous function ..., Johannes Schindelin, (Thu Feb 28, 6:54 pm)
Re: [PATCH 22/40] Windows: Implement asynchronous function ..., Johannes Schindelin, (Fri Feb 29, 3:26 am)
Re: [PATCH 04/40] Windows: Use the Windows style PATH sepa ..., Johannes Schindelin, (Fri Feb 29, 5:19 am)
Re: [PATCH 04/40] Windows: Use the Windows style PATH sepa ..., Johannes Schindelin, (Fri Feb 29, 5:59 am)
Re: [PATCH 03/40] Add target architecture MinGW., Johannes Sixt, (Fri Feb 29, 2:03 pm)
Re: [PATCH 02/40] Compile some programs only conditionally., Johannes Schindelin, (Fri Feb 29, 2:53 pm)
Re: [PATCH 03/40] Add target architecture MinGW., Johannes Schindelin, (Fri Feb 29, 2:54 pm)
Re: [PATCH 20/40] Windows: A rudimentary poll() emulation., Robin Rosenberg, (Sat Mar 1, 8:48 am)
Re: [PATCH 00/40] MinGW port, Johannes Sixt, (Sun Mar 2, 2:20 pm)
Re: [PATCH 00/40] MinGW port, Johannes Schindelin, (Sun Mar 2, 3:07 pm)
Re: [PATCH 00/40] MinGW port, Johannes Sixt, (Mon Mar 3, 11:34 am)
Re: [PATCH 03/40] Add target architecture MinGW., Johannes Sixt, (Wed Mar 5, 2:21 pm)
Re: [PATCH 03/40] Add target architecture MinGW., Johannes Schindelin, (Wed Mar 5, 3:18 pm)
Re: [PATCH 03/40] Add target architecture MinGW., Junio C Hamano, (Wed Mar 5, 3:22 pm)
Re: [PATCH 03/40] Add target architecture MinGW., Johannes Schindelin, (Wed Mar 5, 3:28 pm)
Re: [PATCH 03/40] Add target architecture MinGW., Junio C Hamano, (Wed Mar 5, 3:51 pm)
Re: [PATCH 03/40] Add target architecture MinGW., Johannes Schindelin, (Wed Mar 5, 5:11 pm)
[PATCH 1/2] Add strbuf_initf(), Johannes Schindelin, (Wed Mar 5, 6:14 pm)
[PATCH 2/2] format-patch: add --reviewed-by=&lt;ident&gt;, Johannes Schindelin, (Wed Mar 5, 6:15 pm)
Re: [PATCH 1/2] Add strbuf_initf(), Mike Hommey, (Wed Mar 5, 11:33 pm)
Re: [PATCH 1/2] Add strbuf_initf(), Reece Dunn, (Thu Mar 6, 2:03 am)
Re: [PATCH 2/2] format-patch: add --reviewed-by=&lt;ident&gt;, Johannes Schindelin, (Thu Mar 6, 3:40 am)
Re: [PATCH 1/2] Add strbuf_initf(), Johannes Schindelin, (Thu Mar 6, 3:53 am)
Re: [PATCH 1/2] Add strbuf_initf(), Johannes Schindelin, (Thu Mar 6, 3:55 am)
Re: [PATCH 1/2] Add strbuf_initf(), Reece Dunn, (Thu Mar 6, 4:53 am)
Re: [PATCH 1/2] Add strbuf_initf(), Jeff King, (Thu Mar 6, 5:09 am)
Re: [PATCH 1/2] Add strbuf_initf(), Johannes Schindelin, (Thu Mar 6, 5:52 am)
[PATCH 1/2 v2] Add strbuf_vaddf(), use it in strbuf_addf() ..., Johannes Schindelin, (Thu Mar 6, 9:29 am)
Re: [PATCH 1/2 v2] Add strbuf_vaddf(), use it in strbuf_ad ..., Johannes Schindelin, (Thu Mar 6, 9:59 am)
Re: [PATCH 1/2] Add strbuf_initf(), Kristian , (Thu Mar 6, 11:18 am)
Re: [PATCH 1/2] Add strbuf_initf(), Johannes Schindelin, (Thu Mar 6, 11:26 am)
Re: [PATCH 1/2] Add strbuf_initf(), Kristian , (Thu Mar 6, 11:35 am)
Re: [PATCH 1/2] Add strbuf_initf(), Mike Hommey, (Thu Mar 6, 12:10 pm)
Re: [PATCH 03/40] Add target architecture MinGW., Johannes Sixt, (Thu Mar 6, 1:38 pm)
Re: [PATCH 03/40] Add target architecture MinGW., Johannes Sixt, (Tue Mar 11, 2:30 pm)
Re: [PATCH 03/40] Add target architecture MinGW., Johannes Schindelin, (Tue Mar 11, 4:28 pm)
Re: [PATCH 03/40] Add target architecture MinGW., Johannes Sixt, (Wed Mar 12, 3:59 pm)
Re: [PATCH 03/40] Add target architecture MinGW., Johannes Schindelin, (Wed Mar 12, 4:06 pm)