@matheusbsbs / matheus-bagliano / commits / 8385abfda5
Fork 0

Windows: Handle absolute paths in safe_create_leading_directories().

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>

Johannes Sixt committed Nov 30, 2007 at 21:36 UTC 8385abfda533819be9fbec436230ccd7be4bcda8
1 file changed +8 -4
sha1_file.c
+8 -4
@@ -83,14 +83,18 @@ int get_sha1_hex(const char *hex, unsigned char *sha1)
83 return 0;
84 }
85
86 +static inline int offset_1st_component(const char *path)
87 +{
88 + if (has_dos_drive_prefix(path))
89 + return 2 + (path[2] == '/');
90 + return *path == '/';
91 +}
92 +
93 int safe_create_leading_directories(char *path)
94 {
88 - char *pos = path;
95 + char *pos = path + offset_1st_component(path);
96 struct stat st;
97
91 - if (is_absolute_path(path))
92 - pos++;
93 -
98 while (pos) {
99 pos = strchr(pos, '/');
100 if (!pos)