]> git.ipfire.org Git - thirdparty/git.git/blobdiff - read-cache.c
mingw: safeguard better against backslashes in file names
[thirdparty/git.git] / read-cache.c
index 2c1409491d015c78a627348f36b83b21a2fec19a..f9c8f1948af7605606e43855e76c1699537e2a4e 100644 (file)
@@ -959,11 +959,14 @@ static int verify_dotfile(const char *rest, unsigned mode)
 
 int verify_path(const char *path, unsigned mode)
 {
-       char c;
+       char c = 0;
 
        if (has_dos_drive_prefix(path))
                return 0;
 
+       if (!is_valid_path(path))
+               return 0;
+
        goto inside;
        for (;;) {
                if (!c)
@@ -971,6 +974,7 @@ int verify_path(const char *path, unsigned mode)
                if (is_dir_sep(c)) {
 inside:
                        if (protect_hfs) {
+
                                if (is_hfs_dotgit(path))
                                        return 0;
                                if (S_ISLNK(mode)) {
@@ -979,6 +983,10 @@ inside:
                                }
                        }
                        if (protect_ntfs) {
+#ifdef GIT_WINDOWS_NATIVE
+                               if (c == '\\')
+                                       return 0;
+#endif
                                if (is_ntfs_dotgit(path))
                                        return 0;
                                if (S_ISLNK(mode)) {
@@ -991,7 +999,15 @@ inside:
                        if ((c == '.' && !verify_dotfile(path, mode)) ||
                            is_dir_sep(c) || c == '\0')
                                return 0;
+               } else if (c == '\\' && protect_ntfs) {
+                       if (is_ntfs_dotgit(path))
+                               return 0;
+                       if (S_ISLNK(mode)) {
+                               if (is_ntfs_dotgitmodules(path))
+                                       return 0;
+                       }
                }
+
                c = *path++;
        }
 }
@@ -1276,7 +1292,7 @@ static int add_index_entry_with_check(struct index_state *istate, struct cache_e
         */
        if (istate->cache_nr > 0 &&
                strcmp(ce->name, istate->cache[istate->cache_nr - 1]->name) > 0)
-               pos = -istate->cache_nr - 1;
+               pos = index_pos_to_insert_pos(istate->cache_nr);
        else
                pos = index_name_stage_pos(istate, ce->name, ce_namelen(ce), ce_stage(ce));
 
@@ -1915,7 +1931,7 @@ static size_t estimate_cache_size(size_t ondisk_size, unsigned int entries)
        /*
         * Account for potential alignment differences.
         */
-       per_entry += align_padding_size(sizeof(struct cache_entry), -sizeof(struct ondisk_cache_entry));
+       per_entry += align_padding_size(per_entry, 0);
        return ondisk_size + entries * per_entry;
 }