Coverage Report

Created: 2026-01-17 06:09

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libgit2/src/util/fs_path.h
Line
Count
Source
1
/*
2
 * Copyright (C) the libgit2 contributors. All rights reserved.
3
 *
4
 * This file is part of libgit2, distributed under the GNU GPL v2 with
5
 * a Linking Exception. For full terms see the included COPYING file.
6
 */
7
#ifndef INCLUDE_fs_path_h__
8
#define INCLUDE_fs_path_h__
9
10
#include "git2_util.h"
11
12
#include "posix.h"
13
#include "str.h"
14
#include "vector.h"
15
#include "utf8.h"
16
17
/**
18
 * Path manipulation utils
19
 *
20
 * These are path utilities that munge paths without actually
21
 * looking at the real filesystem.
22
 */
23
24
/*
25
 * The dirname() function shall take a pointer to a character string
26
 * that contains a pathname, and return a pointer to a string that is a
27
 * pathname of the parent directory of that file. Trailing '/' characters
28
 * in the path are not counted as part of the path.
29
 *
30
 * If path does not contain a '/', then dirname() shall return a pointer to
31
 * the string ".". If path is a null pointer or points to an empty string,
32
 * dirname() shall return a pointer to the string "." .
33
 *
34
 * The `git_fs_path_dirname` implementation is thread safe. The returned
35
 * string must be manually free'd.
36
 *
37
 * The `git_fs_path_dirname_r` implementation writes the dirname to a `git_str`
38
 * if the buffer pointer is not NULL.
39
 * It returns an error code < 0 if there is an allocation error, otherwise
40
 * the length of the dirname (which will be > 0).
41
 */
42
extern char *git_fs_path_dirname(const char *path);
43
extern int git_fs_path_dirname_r(git_str *buffer, const char *path);
44
45
/*
46
 * This function returns the basename of the file, which is the last
47
 * part of its full name given by fname, with the drive letter and
48
 * leading directories stripped off. For example, the basename of
49
 * c:/foo/bar/file.ext is file.ext, and the basename of a:foo is foo.
50
 *
51
 * Trailing slashes and backslashes are significant: the basename of
52
 * c:/foo/bar/ is an empty string after the rightmost slash.
53
 *
54
 * The `git_fs_path_basename` implementation is thread safe. The returned
55
 * string must be manually free'd.
56
 *
57
 * The `git_fs_path_basename_r` implementation writes the basename to a `git_str`.
58
 * It returns an error code < 0 if there is an allocation error, otherwise
59
 * the length of the basename (which will be >= 0).
60
 */
61
extern char *git_fs_path_basename(const char *path);
62
extern int git_fs_path_basename_r(git_str *buffer, const char *path);
63
64
/* Return the offset of the start of the basename.  Unlike the other
65
 * basename functions, this returns 0 if the path is empty.
66
 */
67
extern size_t git_fs_path_basename_offset(git_str *buffer);
68
69
/**
70
 * Find offset to root of path if path has one.
71
 *
72
 * This will return a number >= 0 which is the offset to the start of the
73
 * path, if the path is rooted (i.e. "/rooted/path" returns 0 and
74
 * "c:/windows/rooted/path" returns 2).  If the path is not rooted, this
75
 * returns -1.
76
 */
77
extern int git_fs_path_root(const char *path);
78
79
/**
80
 * Ensure path has a trailing '/'.
81
 */
82
extern int git_fs_path_to_dir(git_str *path);
83
84
/**
85
 * Ensure string has a trailing '/' if there is space for it.
86
 */
87
extern void git_fs_path_string_to_dir(char *path, size_t size);
88
89
/**
90
 * Provides the length of the given path string with no trailing
91
 * slashes.
92
 */
93
size_t git_fs_path_dirlen(const char *path);
94
95
/**
96
 * Returns nonzero if the given path is a filesystem root; on Windows, this
97
 * means a drive letter (eg `A:/`, `C:\`). On POSIX this is `/`.
98
 */
99
GIT_INLINE(int) git_fs_path_is_root(const char *name)
100
0
{
101
#ifdef GIT_WIN32
102
  if (((name[0] >= 'A' && name[0] <= 'Z') || (name[0] >= 'a' && name[0] <= 'z')) &&
103
        name[1] == ':' &&
104
       (name[2] == '/' || name[2] == '\\') &&
105
        name[3] == '\0')
106
    return 1;
107
#endif
108
109
0
  return (name[0] == '/' && name[1] == '\0');
110
0
}
Unexecuted instantiation: fuzzer_utils.c:git_fs_path_is_root
Unexecuted instantiation: indexer.c:git_fs_path_is_root
Unexecuted instantiation: libgit2.c:git_fs_path_is_root
Unexecuted instantiation: merge_driver.c:git_fs_path_is_root
Unexecuted instantiation: merge_file.c:git_fs_path_is_root
Unexecuted instantiation: mwindow.c:git_fs_path_is_root
Unexecuted instantiation: object.c:git_fs_path_is_root
Unexecuted instantiation: object_api.c:git_fs_path_is_root
Unexecuted instantiation: odb.c:git_fs_path_is_root
Unexecuted instantiation: odb_loose.c:git_fs_path_is_root
Unexecuted instantiation: odb_mempack.c:git_fs_path_is_root
Unexecuted instantiation: odb_pack.c:git_fs_path_is_root
Unexecuted instantiation: oid.c:git_fs_path_is_root
Unexecuted instantiation: pack-objects.c:git_fs_path_is_root
Unexecuted instantiation: pack.c:git_fs_path_is_root
Unexecuted instantiation: repository.c:git_fs_path_is_root
Unexecuted instantiation: revparse.c:git_fs_path_is_root
Unexecuted instantiation: revwalk.c:git_fs_path_is_root
Unexecuted instantiation: settings.c:git_fs_path_is_root
Unexecuted instantiation: submodule.c:git_fs_path_is_root
Unexecuted instantiation: sysdir.c:git_fs_path_is_root
Unexecuted instantiation: tag.c:git_fs_path_is_root
Unexecuted instantiation: smart_protocol.c:git_fs_path_is_root
Unexecuted instantiation: tree.c:git_fs_path_is_root
Unexecuted instantiation: worktree.c:git_fs_path_is_root
Unexecuted instantiation: filebuf.c:git_fs_path_is_root
Unexecuted instantiation: fs_path.c:git_fs_path_is_root
Unexecuted instantiation: futils.c:git_fs_path_is_root
Unexecuted instantiation: posix.c:git_fs_path_is_root
Unexecuted instantiation: attr.c:git_fs_path_is_root
Unexecuted instantiation: attr_file.c:git_fs_path_is_root
Unexecuted instantiation: attrcache.c:git_fs_path_is_root
Unexecuted instantiation: blob.c:git_fs_path_is_root
Unexecuted instantiation: branch.c:git_fs_path_is_root
Unexecuted instantiation: cache.c:git_fs_path_is_root
Unexecuted instantiation: checkout.c:git_fs_path_is_root
Unexecuted instantiation: clone.c:git_fs_path_is_root
Unexecuted instantiation: commit.c:git_fs_path_is_root
Unexecuted instantiation: commit_graph.c:git_fs_path_is_root
Unexecuted instantiation: commit_list.c:git_fs_path_is_root
Unexecuted instantiation: config.c:git_fs_path_is_root
Unexecuted instantiation: config_cache.c:git_fs_path_is_root
Unexecuted instantiation: config_file.c:git_fs_path_is_root
Unexecuted instantiation: config_list.c:git_fs_path_is_root
Unexecuted instantiation: config_parse.c:git_fs_path_is_root
Unexecuted instantiation: config_snapshot.c:git_fs_path_is_root
Unexecuted instantiation: delta.c:git_fs_path_is_root
Unexecuted instantiation: diff.c:git_fs_path_is_root
Unexecuted instantiation: diff_driver.c:git_fs_path_is_root
Unexecuted instantiation: diff_generate.c:git_fs_path_is_root
Unexecuted instantiation: diff_print.c:git_fs_path_is_root
Unexecuted instantiation: diff_tform.c:git_fs_path_is_root
Unexecuted instantiation: email.c:git_fs_path_is_root
Unexecuted instantiation: filter.c:git_fs_path_is_root
Unexecuted instantiation: grafts.c:git_fs_path_is_root
Unexecuted instantiation: hashsig.c:git_fs_path_is_root
Unexecuted instantiation: ident.c:git_fs_path_is_root
Unexecuted instantiation: index.c:git_fs_path_is_root
Unexecuted instantiation: iterator.c:git_fs_path_is_root
Unexecuted instantiation: mailmap.c:git_fs_path_is_root
Unexecuted instantiation: merge.c:git_fs_path_is_root
Unexecuted instantiation: midx.c:git_fs_path_is_root
Unexecuted instantiation: patch.c:git_fs_path_is_root
Unexecuted instantiation: patch_generate.c:git_fs_path_is_root
Unexecuted instantiation: path.c:git_fs_path_is_root
Unexecuted instantiation: pathspec.c:git_fs_path_is_root
Unexecuted instantiation: push.c:git_fs_path_is_root
Unexecuted instantiation: refdb.c:git_fs_path_is_root
Unexecuted instantiation: refdb_fs.c:git_fs_path_is_root
Unexecuted instantiation: reflog.c:git_fs_path_is_root
Unexecuted instantiation: refs.c:git_fs_path_is_root
Unexecuted instantiation: remote.c:git_fs_path_is_root
Unexecuted instantiation: signature.c:git_fs_path_is_root
Unexecuted instantiation: transaction.c:git_fs_path_is_root
Unexecuted instantiation: transport.c:git_fs_path_is_root
Unexecuted instantiation: local.c:git_fs_path_is_root
Unexecuted instantiation: tree-cache.c:git_fs_path_is_root
Unexecuted instantiation: sortedcache.c:git_fs_path_is_root
Unexecuted instantiation: crlf.c:git_fs_path_is_root
Unexecuted instantiation: diff_file.c:git_fs_path_is_root
Unexecuted instantiation: diff_stats.c:git_fs_path_is_root
Unexecuted instantiation: diff_xdiff.c:git_fs_path_is_root
Unexecuted instantiation: fetch.c:git_fs_path_is_root
Unexecuted instantiation: fetchhead.c:git_fs_path_is_root
Unexecuted instantiation: graph.c:git_fs_path_is_root
Unexecuted instantiation: ignore.c:git_fs_path_is_root
111
112
/**
113
 * Taken from git.git; returns nonzero if the given path is "." or "..".
114
 */
115
GIT_INLINE(int) git_fs_path_is_dot_or_dotdot(const char *name)
116
0
{
117
0
  return (name[0] == '.' &&
118
0
        (name[1] == '\0' ||
119
0
        (name[1] == '.' && name[2] == '\0')));
120
0
}
Unexecuted instantiation: fuzzer_utils.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: indexer.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: libgit2.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: merge_driver.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: merge_file.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: mwindow.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: object.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: object_api.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: odb.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: odb_loose.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: odb_mempack.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: odb_pack.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: oid.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: pack-objects.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: pack.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: repository.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: revparse.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: revwalk.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: settings.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: submodule.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: sysdir.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: tag.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: smart_protocol.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: tree.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: worktree.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: filebuf.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: fs_path.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: futils.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: posix.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: attr.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: attr_file.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: attrcache.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: blob.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: branch.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: cache.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: checkout.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: clone.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: commit.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: commit_graph.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: commit_list.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: config.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: config_cache.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: config_file.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: config_list.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: config_parse.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: config_snapshot.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: delta.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: diff.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: diff_driver.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: diff_generate.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: diff_print.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: diff_tform.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: email.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: filter.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: grafts.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: hashsig.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: ident.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: index.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: iterator.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: mailmap.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: merge.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: midx.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: patch.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: patch_generate.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: path.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: pathspec.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: push.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: refdb.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: refdb_fs.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: reflog.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: refs.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: remote.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: signature.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: transaction.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: transport.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: local.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: tree-cache.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: sortedcache.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: crlf.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: diff_file.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: diff_stats.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: diff_xdiff.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: fetch.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: fetchhead.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: graph.c:git_fs_path_is_dot_or_dotdot
Unexecuted instantiation: ignore.c:git_fs_path_is_dot_or_dotdot
121
122
#ifdef GIT_WIN32
123
GIT_INLINE(int) git_fs_path_is_dot_or_dotdotW(const wchar_t *name)
124
{
125
  return (name[0] == L'.' &&
126
        (name[1] == L'\0' ||
127
        (name[1] == L'.' && name[2] == L'\0')));
128
}
129
130
#define git_fs_path_is_absolute(p) \
131
  (git__isalpha((p)[0]) && (p)[1] == ':' && ((p)[2] == '\\' || (p)[2] == '/'))
132
133
#define git_fs_path_is_dirsep(p) \
134
  ((p) == '/' || (p) == '\\')
135
136
/**
137
 * Convert backslashes in path to forward slashes.
138
 */
139
GIT_INLINE(void) git_fs_path_mkposix(char *path)
140
{
141
  while (*path) {
142
    if (*path == '\\')
143
      *path = '/';
144
145
    path++;
146
  }
147
}
148
#else
149
# define git_fs_path_mkposix(p) /* blank */
150
151
#define git_fs_path_is_absolute(p) \
152
0
  ((p)[0] == '/')
153
154
#define git_fs_path_is_dirsep(p) \
155
0
  ((p) == '/')
156
157
#endif
158
159
/**
160
 * Check if string is a relative path (i.e. starts with "./" or "../")
161
 */
162
GIT_INLINE(int) git_fs_path_is_relative(const char *p)
163
0
{
164
0
  return (p[0] == '.' && (p[1] == '/' || (p[1] == '.' && p[2] == '/')));
165
0
}
Unexecuted instantiation: fuzzer_utils.c:git_fs_path_is_relative
Unexecuted instantiation: indexer.c:git_fs_path_is_relative
Unexecuted instantiation: libgit2.c:git_fs_path_is_relative
Unexecuted instantiation: merge_driver.c:git_fs_path_is_relative
Unexecuted instantiation: merge_file.c:git_fs_path_is_relative
Unexecuted instantiation: mwindow.c:git_fs_path_is_relative
Unexecuted instantiation: object.c:git_fs_path_is_relative
Unexecuted instantiation: object_api.c:git_fs_path_is_relative
Unexecuted instantiation: odb.c:git_fs_path_is_relative
Unexecuted instantiation: odb_loose.c:git_fs_path_is_relative
Unexecuted instantiation: odb_mempack.c:git_fs_path_is_relative
Unexecuted instantiation: odb_pack.c:git_fs_path_is_relative
Unexecuted instantiation: oid.c:git_fs_path_is_relative
Unexecuted instantiation: pack-objects.c:git_fs_path_is_relative
Unexecuted instantiation: pack.c:git_fs_path_is_relative
Unexecuted instantiation: repository.c:git_fs_path_is_relative
Unexecuted instantiation: revparse.c:git_fs_path_is_relative
Unexecuted instantiation: revwalk.c:git_fs_path_is_relative
Unexecuted instantiation: settings.c:git_fs_path_is_relative
Unexecuted instantiation: submodule.c:git_fs_path_is_relative
Unexecuted instantiation: sysdir.c:git_fs_path_is_relative
Unexecuted instantiation: tag.c:git_fs_path_is_relative
Unexecuted instantiation: smart_protocol.c:git_fs_path_is_relative
Unexecuted instantiation: tree.c:git_fs_path_is_relative
Unexecuted instantiation: worktree.c:git_fs_path_is_relative
Unexecuted instantiation: filebuf.c:git_fs_path_is_relative
Unexecuted instantiation: fs_path.c:git_fs_path_is_relative
Unexecuted instantiation: futils.c:git_fs_path_is_relative
Unexecuted instantiation: posix.c:git_fs_path_is_relative
Unexecuted instantiation: attr.c:git_fs_path_is_relative
Unexecuted instantiation: attr_file.c:git_fs_path_is_relative
Unexecuted instantiation: attrcache.c:git_fs_path_is_relative
Unexecuted instantiation: blob.c:git_fs_path_is_relative
Unexecuted instantiation: branch.c:git_fs_path_is_relative
Unexecuted instantiation: cache.c:git_fs_path_is_relative
Unexecuted instantiation: checkout.c:git_fs_path_is_relative
Unexecuted instantiation: clone.c:git_fs_path_is_relative
Unexecuted instantiation: commit.c:git_fs_path_is_relative
Unexecuted instantiation: commit_graph.c:git_fs_path_is_relative
Unexecuted instantiation: commit_list.c:git_fs_path_is_relative
Unexecuted instantiation: config.c:git_fs_path_is_relative
Unexecuted instantiation: config_cache.c:git_fs_path_is_relative
Unexecuted instantiation: config_file.c:git_fs_path_is_relative
Unexecuted instantiation: config_list.c:git_fs_path_is_relative
Unexecuted instantiation: config_parse.c:git_fs_path_is_relative
Unexecuted instantiation: config_snapshot.c:git_fs_path_is_relative
Unexecuted instantiation: delta.c:git_fs_path_is_relative
Unexecuted instantiation: diff.c:git_fs_path_is_relative
Unexecuted instantiation: diff_driver.c:git_fs_path_is_relative
Unexecuted instantiation: diff_generate.c:git_fs_path_is_relative
Unexecuted instantiation: diff_print.c:git_fs_path_is_relative
Unexecuted instantiation: diff_tform.c:git_fs_path_is_relative
Unexecuted instantiation: email.c:git_fs_path_is_relative
Unexecuted instantiation: filter.c:git_fs_path_is_relative
Unexecuted instantiation: grafts.c:git_fs_path_is_relative
Unexecuted instantiation: hashsig.c:git_fs_path_is_relative
Unexecuted instantiation: ident.c:git_fs_path_is_relative
Unexecuted instantiation: index.c:git_fs_path_is_relative
Unexecuted instantiation: iterator.c:git_fs_path_is_relative
Unexecuted instantiation: mailmap.c:git_fs_path_is_relative
Unexecuted instantiation: merge.c:git_fs_path_is_relative
Unexecuted instantiation: midx.c:git_fs_path_is_relative
Unexecuted instantiation: patch.c:git_fs_path_is_relative
Unexecuted instantiation: patch_generate.c:git_fs_path_is_relative
Unexecuted instantiation: path.c:git_fs_path_is_relative
Unexecuted instantiation: pathspec.c:git_fs_path_is_relative
Unexecuted instantiation: push.c:git_fs_path_is_relative
Unexecuted instantiation: refdb.c:git_fs_path_is_relative
Unexecuted instantiation: refdb_fs.c:git_fs_path_is_relative
Unexecuted instantiation: reflog.c:git_fs_path_is_relative
Unexecuted instantiation: refs.c:git_fs_path_is_relative
Unexecuted instantiation: remote.c:git_fs_path_is_relative
Unexecuted instantiation: signature.c:git_fs_path_is_relative
Unexecuted instantiation: transaction.c:git_fs_path_is_relative
Unexecuted instantiation: transport.c:git_fs_path_is_relative
Unexecuted instantiation: local.c:git_fs_path_is_relative
Unexecuted instantiation: tree-cache.c:git_fs_path_is_relative
Unexecuted instantiation: sortedcache.c:git_fs_path_is_relative
Unexecuted instantiation: crlf.c:git_fs_path_is_relative
Unexecuted instantiation: diff_file.c:git_fs_path_is_relative
Unexecuted instantiation: diff_stats.c:git_fs_path_is_relative
Unexecuted instantiation: diff_xdiff.c:git_fs_path_is_relative
Unexecuted instantiation: fetch.c:git_fs_path_is_relative
Unexecuted instantiation: fetchhead.c:git_fs_path_is_relative
Unexecuted instantiation: graph.c:git_fs_path_is_relative
Unexecuted instantiation: ignore.c:git_fs_path_is_relative
166
167
/**
168
 * Check if string is at end of path segment (i.e. looking at '/' or '\0')
169
 */
170
GIT_INLINE(int) git_fs_path_at_end_of_segment(const char *p)
171
0
{
172
0
  return !*p || *p == '/';
173
0
}
Unexecuted instantiation: fuzzer_utils.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: indexer.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: libgit2.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: merge_driver.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: merge_file.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: mwindow.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: object.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: object_api.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: odb.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: odb_loose.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: odb_mempack.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: odb_pack.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: oid.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: pack-objects.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: pack.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: repository.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: revparse.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: revwalk.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: settings.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: submodule.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: sysdir.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: tag.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: smart_protocol.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: tree.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: worktree.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: filebuf.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: fs_path.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: futils.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: posix.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: attr.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: attr_file.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: attrcache.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: blob.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: branch.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: cache.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: checkout.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: clone.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: commit.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: commit_graph.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: commit_list.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: config.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: config_cache.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: config_file.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: config_list.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: config_parse.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: config_snapshot.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: delta.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: diff.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: diff_driver.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: diff_generate.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: diff_print.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: diff_tform.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: email.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: filter.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: grafts.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: hashsig.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: ident.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: index.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: iterator.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: mailmap.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: merge.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: midx.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: patch.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: patch_generate.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: path.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: pathspec.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: push.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: refdb.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: refdb_fs.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: reflog.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: refs.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: remote.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: signature.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: transaction.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: transport.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: local.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: tree-cache.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: sortedcache.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: crlf.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: diff_file.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: diff_stats.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: diff_xdiff.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: fetch.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: fetchhead.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: graph.c:git_fs_path_at_end_of_segment
Unexecuted instantiation: ignore.c:git_fs_path_at_end_of_segment
174
175
extern int git__percent_decode(git_str *decoded_out, const char *input);
176
177
/**
178
 * Extract path from file:// URL.
179
 */
180
extern int git_fs_path_fromurl(git_str *local_path_out, const char *file_url);
181
182
183
/**
184
 * Path filesystem utils
185
 *
186
 * These are path utilities that actually access the filesystem.
187
 */
188
189
/**
190
 * Check if a file exists and can be accessed.
191
 * @return true or false
192
 */
193
extern bool git_fs_path_exists(const char *path);
194
195
/**
196
 * Check if the given path points to a directory.
197
 * @return true or false
198
 */
199
extern bool git_fs_path_isdir(const char *path);
200
201
/**
202
 * Check if the given path points to a regular file.
203
 * @return true or false
204
 */
205
extern bool git_fs_path_isfile(const char *path);
206
207
/**
208
 * Check if the given path points to an executable.
209
 * @return true or false
210
 */
211
extern bool git_fs_path_isexecutable(const char *path);
212
213
/**
214
 * Check if the given path points to a symbolic link.
215
 * @return true or false
216
 */
217
extern bool git_fs_path_islink(const char *path);
218
219
/**
220
 * Check if the given path is a directory, and is empty.
221
 */
222
extern bool git_fs_path_is_empty_dir(const char *path);
223
224
/**
225
 * Stat a file and/or link and set error if needed.
226
 */
227
extern int git_fs_path_lstat(const char *path, struct stat *st);
228
229
/**
230
 * Check if the parent directory contains the item.
231
 *
232
 * @param dir Directory to check.
233
 * @param item Item that might be in the directory.
234
 * @return 0 if item exists in directory, <0 otherwise.
235
 */
236
extern bool git_fs_path_contains(git_str *dir, const char *item);
237
238
/**
239
 * Check if the given path contains the given subdirectory.
240
 *
241
 * @param parent Directory path that might contain subdir
242
 * @param subdir Subdirectory name to look for in parent
243
 * @return true if subdirectory exists, false otherwise.
244
 */
245
extern bool git_fs_path_contains_dir(git_str *parent, const char *subdir);
246
247
/**
248
 * Determine the common directory length between two paths, including
249
 * the final path separator.  For example, given paths 'a/b/c/1.txt
250
 * and 'a/b/c/d/2.txt', the common directory is 'a/b/c/', and this
251
 * will return the length of the string 'a/b/c/', which is 6.
252
 *
253
 * @param one The first path
254
 * @param two The second path
255
 * @return The length of the common directory
256
 */
257
extern size_t git_fs_path_common_dirlen(const char *one, const char *two);
258
259
/**
260
 * Make the path relative to the given parent path.
261
 *
262
 * @param path The path to make relative
263
 * @param parent The parent path to make path relative to
264
 * @return 0 if path was made relative, GIT_ENOTFOUND
265
 *         if there was not common root between the paths,
266
 *         or <0.
267
 */
268
extern int git_fs_path_make_relative(git_str *path, const char *parent);
269
270
/**
271
 * Check if the given path contains the given file.
272
 *
273
 * @param dir Directory path that might contain file
274
 * @param file File name to look for in parent
275
 * @return true if file exists, false otherwise.
276
 */
277
extern bool git_fs_path_contains_file(git_str *dir, const char *file);
278
279
/**
280
 * Prepend base to unrooted path or just copy path over.
281
 *
282
 * This will optionally return the index into the path where the "root"
283
 * is, either the end of the base directory prefix or the path root.
284
 */
285
extern int git_fs_path_join_unrooted(
286
  git_str *path_out, const char *path, const char *base, ssize_t *root_at);
287
288
/**
289
 * Removes multiple occurrences of '/' in a row, squashing them into a
290
 * single '/'.
291
 */
292
extern void git_fs_path_squash_slashes(git_str *path);
293
294
/**
295
 * Clean up path, prepending base if it is not already rooted.
296
 */
297
extern int git_fs_path_prettify(git_str *path_out, const char *path, const char *base);
298
299
/**
300
 * Clean up path, prepending base if it is not already rooted and
301
 * appending a slash.
302
 */
303
extern int git_fs_path_prettify_dir(git_str *path_out, const char *path, const char *base);
304
305
/**
306
 * Get a directory from a path.
307
 *
308
 * If path is a directory, this acts like `git_fs_path_prettify_dir`
309
 * (cleaning up path and appending a '/').  If path is a normal file,
310
 * this prettifies it, then removed the filename a la dirname and
311
 * appends the trailing '/'.  If the path does not exist, it is
312
 * treated like a regular filename.
313
 */
314
extern int git_fs_path_find_dir(git_str *dir);
315
316
/**
317
 * Resolve relative references within a path.
318
 *
319
 * This eliminates "./" and "../" relative references inside a path,
320
 * as well as condensing multiple slashes into single ones.  It will
321
 * not touch the path before the "ceiling" length.
322
 *
323
 * Additionally, this will recognize an "c:/" drive prefix or a "xyz://" URL
324
 * prefix and not touch that part of the path.
325
 */
326
extern int git_fs_path_resolve_relative(git_str *path, size_t ceiling);
327
328
/**
329
 * Apply a relative path to base path.
330
 *
331
 * Note that the base path could be a filename or a URL and this
332
 * should still work.  The relative path is walked segment by segment
333
 * with three rules: series of slashes will be condensed to a single
334
 * slash, "." will be eaten with no change, and ".." will remove a
335
 * segment from the base path.
336
 */
337
extern int git_fs_path_apply_relative(git_str *target, const char *relpath);
338
339
enum {
340
  GIT_FS_PATH_DIR_IGNORE_CASE = (1u << 0),
341
  GIT_FS_PATH_DIR_PRECOMPOSE_UNICODE = (1u << 1),
342
  GIT_FS_PATH_DIR_INCLUDE_DOT_AND_DOTDOT = (1u << 2),
343
};
344
345
/**
346
 * Walk each directory entry, except '.' and '..', calling fn(state).
347
 *
348
 * @param pathbuf Buffer the function reads the initial directory
349
 *    path from, and updates with each successive entry's name.
350
 * @param flags Combination of GIT_FS_PATH_DIR flags.
351
 * @param callback Callback for each entry. Passed the `payload` and each
352
 *    successive path inside the directory as a full path.  This may
353
 *    safely append text to the pathbuf if needed.  Return non-zero to
354
 *    cancel iteration (and return value will be propagated back).
355
 * @param payload Passed to callback as first argument.
356
 * @return 0 on success or error code from OS error or from callback
357
 */
358
extern int git_fs_path_direach(
359
  git_str *pathbuf,
360
  uint32_t flags,
361
  int (*callback)(void *payload, git_str *path),
362
  void *payload);
363
364
/**
365
 * Sort function to order two paths
366
 */
367
extern int git_fs_path_cmp(
368
  const char *name1, size_t len1, int isdir1,
369
  const char *name2, size_t len2, int isdir2,
370
  int (*compare)(const char *, const char *, size_t));
371
372
/**
373
 * Invoke callback up path directory by directory until the ceiling is
374
 * reached (inclusive of a final call at the root_path).
375
 *
376
 * Returning anything other than 0 from the callback function
377
 * will stop the iteration and propagate the error to the caller.
378
 *
379
 * @param pathbuf Buffer the function reads the directory from and
380
 *    and updates with each successive name.
381
 * @param ceiling Prefix of path at which to stop walking up.  If NULL,
382
 *    this will walk all the way up to the root.  If not a prefix of
383
 *    pathbuf, the callback will be invoked a single time on the
384
 *    original input path.
385
 * @param callback Function to invoke on each path.  Passed the `payload`
386
 *    and the buffer containing the current path.  The path should not
387
 *    be modified in any way. Return non-zero to stop iteration.
388
 * @param payload Passed to fn as the first ath.
389
 */
390
extern int git_fs_path_walk_up(
391
  git_str *pathbuf,
392
  const char *ceiling,
393
  int (*callback)(void *payload, const char *path),
394
  void *payload);
395
396
397
enum {
398
  GIT_FS_PATH_NOTEQUAL = 0,
399
  GIT_FS_PATH_EQUAL = 1,
400
  GIT_FS_PATH_PREFIX = 2
401
};
402
403
/*
404
 * Determines if a path is equal to or potentially a child of another.
405
 * @param parent The possible parent
406
 * @param child The possible child
407
 */
408
GIT_INLINE(int) git_fs_path_equal_or_prefixed(
409
  const char *parent,
410
  const char *child,
411
  ssize_t *prefixlen)
412
0
{
413
0
  const char *p = parent, *c = child;
414
0
  int lastslash = 0;
415
416
0
  while (*p && *c) {
417
0
    lastslash = (*p == '/');
418
419
0
    if (*p++ != *c++)
420
0
      return GIT_FS_PATH_NOTEQUAL;
421
0
  }
422
423
0
  if (*p != '\0')
424
0
    return GIT_FS_PATH_NOTEQUAL;
425
426
0
  if (*c == '\0') {
427
0
    if (prefixlen)
428
0
      *prefixlen = p - parent;
429
430
0
    return GIT_FS_PATH_EQUAL;
431
0
  }
432
433
0
  if (*c == '/' || lastslash) {
434
0
    if (prefixlen)
435
0
      *prefixlen = (p - parent) - lastslash;
436
437
0
    return GIT_FS_PATH_PREFIX;
438
0
  }
439
440
0
  return GIT_FS_PATH_NOTEQUAL;
441
0
}
Unexecuted instantiation: fuzzer_utils.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: indexer.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: libgit2.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: merge_driver.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: merge_file.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: mwindow.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: object.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: object_api.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: odb.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: odb_loose.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: odb_mempack.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: odb_pack.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: oid.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: pack-objects.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: pack.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: repository.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: revparse.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: revwalk.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: settings.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: submodule.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: sysdir.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: tag.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: smart_protocol.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: tree.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: worktree.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: filebuf.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: fs_path.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: futils.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: posix.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: attr.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: attr_file.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: attrcache.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: blob.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: branch.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: cache.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: checkout.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: clone.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: commit.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: commit_graph.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: commit_list.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: config.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: config_cache.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: config_file.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: config_list.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: config_parse.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: config_snapshot.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: delta.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: diff.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: diff_driver.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: diff_generate.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: diff_print.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: diff_tform.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: email.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: filter.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: grafts.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: hashsig.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: ident.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: index.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: iterator.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: mailmap.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: merge.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: midx.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: patch.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: patch_generate.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: path.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: pathspec.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: push.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: refdb.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: refdb_fs.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: reflog.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: refs.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: remote.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: signature.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: transaction.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: transport.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: local.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: tree-cache.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: sortedcache.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: crlf.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: diff_file.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: diff_stats.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: diff_xdiff.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: fetch.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: fetchhead.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: graph.c:git_fs_path_equal_or_prefixed
Unexecuted instantiation: ignore.c:git_fs_path_equal_or_prefixed
442
443
/* translate errno to libgit2 error code and set error message */
444
extern int git_fs_path_set_error(
445
  int errno_value, const char *path, const char *action);
446
447
/* check if non-ascii characters are present in filename */
448
extern bool git_fs_path_has_non_ascii(const char *path, size_t pathlen);
449
450
#define GIT_PATH_REPO_ENCODING "UTF-8"
451
452
#ifdef __APPLE__
453
#define GIT_PATH_NATIVE_ENCODING "UTF-8-MAC"
454
#else
455
#define GIT_PATH_NATIVE_ENCODING "UTF-8"
456
#endif
457
458
#ifdef GIT_I18N_ICONV
459
460
#include <iconv.h>
461
462
typedef struct {
463
  iconv_t map;
464
  git_str buf;
465
} git_fs_path_iconv_t;
466
467
#define GIT_PATH_ICONV_INIT { (iconv_t)-1, GIT_STR_INIT }
468
469
/* Init iconv data for converting decomposed UTF-8 to precomposed */
470
extern int git_fs_path_iconv_init_precompose(git_fs_path_iconv_t *ic);
471
472
/* Clear allocated iconv data */
473
extern void git_fs_path_iconv_clear(git_fs_path_iconv_t *ic);
474
475
/*
476
 * Rewrite `in` buffer using iconv map if necessary, replacing `in`
477
 * pointer internal iconv buffer if rewrite happened.  The `in` pointer
478
 * will be left unchanged if no rewrite was needed.
479
 */
480
extern int git_fs_path_iconv(git_fs_path_iconv_t *ic, const char **in, size_t *inlen);
481
482
#endif /* GIT_I18N_ICONV */
483
484
extern bool git_fs_path_does_decompose_unicode(const char *root);
485
486
487
typedef struct git_fs_path_diriter git_fs_path_diriter;
488
489
#if defined(GIT_WIN32) && !defined(__MINGW32__)
490
491
struct git_fs_path_diriter
492
{
493
  git_win32_path path;
494
  size_t parent_len;
495
496
  git_str path_utf8;
497
  size_t parent_utf8_len;
498
499
  HANDLE handle;
500
501
  unsigned int flags;
502
503
  WIN32_FIND_DATAW current;
504
  unsigned int needs_next;
505
};
506
507
#define GIT_FS_PATH_DIRITER_INIT { {0}, 0, GIT_STR_INIT, 0, INVALID_HANDLE_VALUE }
508
509
#else
510
511
struct git_fs_path_diriter
512
{
513
  git_str path;
514
  size_t parent_len;
515
516
  unsigned int flags;
517
518
  DIR *dir;
519
520
#ifdef GIT_I18N_ICONV
521
  git_fs_path_iconv_t ic;
522
#endif
523
};
524
525
0
#define GIT_FS_PATH_DIRITER_INIT { GIT_STR_INIT }
526
527
#endif
528
529
/**
530
 * Initialize a directory iterator.
531
 *
532
 * @param diriter Pointer to a diriter structure that will be setup.
533
 * @param path The path that will be iterated over
534
 * @param flags Directory reader flags
535
 * @return 0 or an error code
536
 */
537
extern int git_fs_path_diriter_init(
538
  git_fs_path_diriter *diriter,
539
  const char *path,
540
  unsigned int flags);
541
542
/**
543
 * Advance the directory iterator.  Will return GIT_ITEROVER when
544
 * the iteration has completed successfully.
545
 *
546
 * @param diriter The directory iterator
547
 * @return 0, GIT_ITEROVER, or an error code
548
 */
549
extern int git_fs_path_diriter_next(git_fs_path_diriter *diriter);
550
551
/**
552
 * Returns the file name of the current item in the iterator.
553
 *
554
 * @param out Pointer to store the path in
555
 * @param out_len Pointer to store the length of the path in
556
 * @param diriter The directory iterator
557
 * @return 0 or an error code
558
 */
559
extern int git_fs_path_diriter_filename(
560
  const char **out,
561
  size_t *out_len,
562
  git_fs_path_diriter *diriter);
563
564
/**
565
 * Returns the full path of the current item in the iterator; that
566
 * is the current filename plus the path of the directory that the
567
 * iterator was constructed with.
568
 *
569
 * @param out Pointer to store the path in
570
 * @param out_len Pointer to store the length of the path in
571
 * @param diriter The directory iterator
572
 * @return 0 or an error code
573
 */
574
extern int git_fs_path_diriter_fullpath(
575
  const char **out,
576
  size_t *out_len,
577
  git_fs_path_diriter *diriter);
578
579
/**
580
 * Performs an `lstat` on the current item in the iterator.
581
 *
582
 * @param out Pointer to store the stat data in
583
 * @param diriter The directory iterator
584
 * @return 0 or an error code
585
 */
586
extern int git_fs_path_diriter_stat(struct stat *out, git_fs_path_diriter *diriter);
587
588
/**
589
 * Closes the directory iterator.
590
 *
591
 * @param diriter The directory iterator
592
 */
593
extern void git_fs_path_diriter_free(git_fs_path_diriter *diriter);
594
595
/**
596
 * Load all directory entries (except '.' and '..') into a vector.
597
 *
598
 * For cases where `git_fs_path_direach()` is not appropriate, this
599
 * allows you to load the filenames in a directory into a vector
600
 * of strings. That vector can then be sorted, iterated, or whatever.
601
 * Remember to free alloc of the allocated strings when you are done.
602
 *
603
 * @param contents Vector to fill with directory entry names.
604
 * @param path The directory to read from.
605
 * @param prefix_len When inserting entries, the trailing part of path
606
 *    will be prefixed after this length.  I.e. given path "/a/b" and
607
 *    prefix_len 3, the entries will look like "b/e1", "b/e2", etc.
608
 * @param flags Combination of GIT_FS_PATH_DIR flags.
609
 */
610
extern int git_fs_path_dirload(
611
  git_vector *contents,
612
  const char *path,
613
  size_t prefix_len,
614
  uint32_t flags);
615
616
617
/* Used for paths to repositories on the filesystem */
618
extern bool git_fs_path_is_local_file_url(const char *file_url);
619
extern int git_fs_path_from_url_or_path(git_str *local_path_out, const char *url_or_path);
620
621
/* Flags to determine path validity in `git_fs_path_isvalid` */
622
0
#define GIT_FS_PATH_REJECT_EMPTY_COMPONENT    (1 << 0)
623
0
#define GIT_FS_PATH_REJECT_TRAVERSAL          (1 << 1)
624
0
#define GIT_FS_PATH_REJECT_SLASH              (1 << 2)
625
0
#define GIT_FS_PATH_REJECT_BACKSLASH          (1 << 3)
626
0
#define GIT_FS_PATH_REJECT_TRAILING_DOT       (1 << 4)
627
0
#define GIT_FS_PATH_REJECT_TRAILING_SPACE     (1 << 5)
628
0
#define GIT_FS_PATH_REJECT_TRAILING_COLON     (1 << 6)
629
0
#define GIT_FS_PATH_REJECT_DOS_PATHS          (1 << 7)
630
0
#define GIT_FS_PATH_REJECT_NT_CHARS           (1 << 8)
631
0
#define GIT_FS_PATH_REJECT_LONG_PATHS         (1 << 9)
632
633
0
#define GIT_FS_PATH_REJECT_MAX                (1 << 9)
634
635
/* Default path safety for writing files to disk: since we use the
636
 * Win32 "File Namespace" APIs ("\\?\") we need to protect from
637
 * paths that the normal Win32 APIs would not write.
638
 */
639
#ifdef GIT_WIN32
640
# define GIT_FS_PATH_REJECT_FILESYSTEM_DEFAULTS \
641
  GIT_FS_PATH_REJECT_EMPTY_COMPONENT | \
642
  GIT_FS_PATH_REJECT_TRAVERSAL | \
643
  GIT_FS_PATH_REJECT_BACKSLASH | \
644
  GIT_FS_PATH_REJECT_TRAILING_DOT | \
645
  GIT_FS_PATH_REJECT_TRAILING_SPACE | \
646
  GIT_FS_PATH_REJECT_TRAILING_COLON | \
647
  GIT_FS_PATH_REJECT_DOS_PATHS | \
648
  GIT_FS_PATH_REJECT_NT_CHARS
649
#else
650
# define GIT_FS_PATH_REJECT_FILESYSTEM_DEFAULTS \
651
0
  GIT_FS_PATH_REJECT_EMPTY_COMPONENT | \
652
0
  GIT_FS_PATH_REJECT_TRAVERSAL
653
#endif
654
655
/**
656
 * Validate a filesystem path; with custom callbacks per-character and
657
 * per-path component.
658
 */
659
extern bool git_fs_path_str_is_valid_ext(
660
  const git_str *path,
661
  unsigned int flags,
662
  bool (*validate_char_cb)(char ch, void *payload),
663
  bool (*validate_component_cb)(const char *component, size_t len, void *payload),
664
  bool (*validate_length_cb)(const char *component, size_t len, size_t utf8_char_len),
665
  void *payload);
666
667
GIT_INLINE(bool) git_fs_path_is_valid_ext(
668
  const char *path,
669
  unsigned int flags,
670
  bool (*validate_char_cb)(char ch, void *payload),
671
  bool (*validate_component_cb)(const char *component, size_t len, void *payload),
672
  bool (*validate_length_cb)(const char *component, size_t len, size_t utf8_char_len),
673
  void *payload)
674
0
{
675
0
  const git_str str = GIT_STR_INIT_CONST(path, SIZE_MAX);
676
0
  return git_fs_path_str_is_valid_ext(
677
0
    &str,
678
0
    flags,
679
0
    validate_char_cb,
680
0
    validate_component_cb,
681
0
    validate_length_cb,
682
0
    payload);
683
0
}
Unexecuted instantiation: fuzzer_utils.c:git_fs_path_is_valid_ext
Unexecuted instantiation: indexer.c:git_fs_path_is_valid_ext
Unexecuted instantiation: libgit2.c:git_fs_path_is_valid_ext
Unexecuted instantiation: merge_driver.c:git_fs_path_is_valid_ext
Unexecuted instantiation: merge_file.c:git_fs_path_is_valid_ext
Unexecuted instantiation: mwindow.c:git_fs_path_is_valid_ext
Unexecuted instantiation: object.c:git_fs_path_is_valid_ext
Unexecuted instantiation: object_api.c:git_fs_path_is_valid_ext
Unexecuted instantiation: odb.c:git_fs_path_is_valid_ext
Unexecuted instantiation: odb_loose.c:git_fs_path_is_valid_ext
Unexecuted instantiation: odb_mempack.c:git_fs_path_is_valid_ext
Unexecuted instantiation: odb_pack.c:git_fs_path_is_valid_ext
Unexecuted instantiation: oid.c:git_fs_path_is_valid_ext
Unexecuted instantiation: pack-objects.c:git_fs_path_is_valid_ext
Unexecuted instantiation: pack.c:git_fs_path_is_valid_ext
Unexecuted instantiation: repository.c:git_fs_path_is_valid_ext
Unexecuted instantiation: revparse.c:git_fs_path_is_valid_ext
Unexecuted instantiation: revwalk.c:git_fs_path_is_valid_ext
Unexecuted instantiation: settings.c:git_fs_path_is_valid_ext
Unexecuted instantiation: submodule.c:git_fs_path_is_valid_ext
Unexecuted instantiation: sysdir.c:git_fs_path_is_valid_ext
Unexecuted instantiation: tag.c:git_fs_path_is_valid_ext
Unexecuted instantiation: smart_protocol.c:git_fs_path_is_valid_ext
Unexecuted instantiation: tree.c:git_fs_path_is_valid_ext
Unexecuted instantiation: worktree.c:git_fs_path_is_valid_ext
Unexecuted instantiation: filebuf.c:git_fs_path_is_valid_ext
Unexecuted instantiation: fs_path.c:git_fs_path_is_valid_ext
Unexecuted instantiation: futils.c:git_fs_path_is_valid_ext
Unexecuted instantiation: posix.c:git_fs_path_is_valid_ext
Unexecuted instantiation: attr.c:git_fs_path_is_valid_ext
Unexecuted instantiation: attr_file.c:git_fs_path_is_valid_ext
Unexecuted instantiation: attrcache.c:git_fs_path_is_valid_ext
Unexecuted instantiation: blob.c:git_fs_path_is_valid_ext
Unexecuted instantiation: branch.c:git_fs_path_is_valid_ext
Unexecuted instantiation: cache.c:git_fs_path_is_valid_ext
Unexecuted instantiation: checkout.c:git_fs_path_is_valid_ext
Unexecuted instantiation: clone.c:git_fs_path_is_valid_ext
Unexecuted instantiation: commit.c:git_fs_path_is_valid_ext
Unexecuted instantiation: commit_graph.c:git_fs_path_is_valid_ext
Unexecuted instantiation: commit_list.c:git_fs_path_is_valid_ext
Unexecuted instantiation: config.c:git_fs_path_is_valid_ext
Unexecuted instantiation: config_cache.c:git_fs_path_is_valid_ext
Unexecuted instantiation: config_file.c:git_fs_path_is_valid_ext
Unexecuted instantiation: config_list.c:git_fs_path_is_valid_ext
Unexecuted instantiation: config_parse.c:git_fs_path_is_valid_ext
Unexecuted instantiation: config_snapshot.c:git_fs_path_is_valid_ext
Unexecuted instantiation: delta.c:git_fs_path_is_valid_ext
Unexecuted instantiation: diff.c:git_fs_path_is_valid_ext
Unexecuted instantiation: diff_driver.c:git_fs_path_is_valid_ext
Unexecuted instantiation: diff_generate.c:git_fs_path_is_valid_ext
Unexecuted instantiation: diff_print.c:git_fs_path_is_valid_ext
Unexecuted instantiation: diff_tform.c:git_fs_path_is_valid_ext
Unexecuted instantiation: email.c:git_fs_path_is_valid_ext
Unexecuted instantiation: filter.c:git_fs_path_is_valid_ext
Unexecuted instantiation: grafts.c:git_fs_path_is_valid_ext
Unexecuted instantiation: hashsig.c:git_fs_path_is_valid_ext
Unexecuted instantiation: ident.c:git_fs_path_is_valid_ext
Unexecuted instantiation: index.c:git_fs_path_is_valid_ext
Unexecuted instantiation: iterator.c:git_fs_path_is_valid_ext
Unexecuted instantiation: mailmap.c:git_fs_path_is_valid_ext
Unexecuted instantiation: merge.c:git_fs_path_is_valid_ext
Unexecuted instantiation: midx.c:git_fs_path_is_valid_ext
Unexecuted instantiation: patch.c:git_fs_path_is_valid_ext
Unexecuted instantiation: patch_generate.c:git_fs_path_is_valid_ext
Unexecuted instantiation: path.c:git_fs_path_is_valid_ext
Unexecuted instantiation: pathspec.c:git_fs_path_is_valid_ext
Unexecuted instantiation: push.c:git_fs_path_is_valid_ext
Unexecuted instantiation: refdb.c:git_fs_path_is_valid_ext
Unexecuted instantiation: refdb_fs.c:git_fs_path_is_valid_ext
Unexecuted instantiation: reflog.c:git_fs_path_is_valid_ext
Unexecuted instantiation: refs.c:git_fs_path_is_valid_ext
Unexecuted instantiation: remote.c:git_fs_path_is_valid_ext
Unexecuted instantiation: signature.c:git_fs_path_is_valid_ext
Unexecuted instantiation: transaction.c:git_fs_path_is_valid_ext
Unexecuted instantiation: transport.c:git_fs_path_is_valid_ext
Unexecuted instantiation: local.c:git_fs_path_is_valid_ext
Unexecuted instantiation: tree-cache.c:git_fs_path_is_valid_ext
Unexecuted instantiation: sortedcache.c:git_fs_path_is_valid_ext
Unexecuted instantiation: crlf.c:git_fs_path_is_valid_ext
Unexecuted instantiation: diff_file.c:git_fs_path_is_valid_ext
Unexecuted instantiation: diff_stats.c:git_fs_path_is_valid_ext
Unexecuted instantiation: diff_xdiff.c:git_fs_path_is_valid_ext
Unexecuted instantiation: fetch.c:git_fs_path_is_valid_ext
Unexecuted instantiation: fetchhead.c:git_fs_path_is_valid_ext
Unexecuted instantiation: graph.c:git_fs_path_is_valid_ext
Unexecuted instantiation: ignore.c:git_fs_path_is_valid_ext
684
685
/**
686
 * Validate a filesystem path.  This ensures that the given path is legal
687
 * and does not contain any "unsafe" components like path traversal ('.'
688
 * or '..'), characters that are inappropriate for lesser filesystems
689
 * (trailing ' ' or ':' characters), or filenames ("component names")
690
 * that are not supported ('AUX', 'COM1").
691
 */
692
GIT_INLINE(bool) git_fs_path_is_valid(
693
  const char *path,
694
  unsigned int flags)
695
0
{
696
0
  const git_str str = GIT_STR_INIT_CONST(path, SIZE_MAX);
697
0
  return git_fs_path_str_is_valid_ext(&str, flags, NULL, NULL, NULL, NULL);
698
0
}
Unexecuted instantiation: fuzzer_utils.c:git_fs_path_is_valid
Unexecuted instantiation: indexer.c:git_fs_path_is_valid
Unexecuted instantiation: libgit2.c:git_fs_path_is_valid
Unexecuted instantiation: merge_driver.c:git_fs_path_is_valid
Unexecuted instantiation: merge_file.c:git_fs_path_is_valid
Unexecuted instantiation: mwindow.c:git_fs_path_is_valid
Unexecuted instantiation: object.c:git_fs_path_is_valid
Unexecuted instantiation: object_api.c:git_fs_path_is_valid
Unexecuted instantiation: odb.c:git_fs_path_is_valid
Unexecuted instantiation: odb_loose.c:git_fs_path_is_valid
Unexecuted instantiation: odb_mempack.c:git_fs_path_is_valid
Unexecuted instantiation: odb_pack.c:git_fs_path_is_valid
Unexecuted instantiation: oid.c:git_fs_path_is_valid
Unexecuted instantiation: pack-objects.c:git_fs_path_is_valid
Unexecuted instantiation: pack.c:git_fs_path_is_valid
Unexecuted instantiation: repository.c:git_fs_path_is_valid
Unexecuted instantiation: revparse.c:git_fs_path_is_valid
Unexecuted instantiation: revwalk.c:git_fs_path_is_valid
Unexecuted instantiation: settings.c:git_fs_path_is_valid
Unexecuted instantiation: submodule.c:git_fs_path_is_valid
Unexecuted instantiation: sysdir.c:git_fs_path_is_valid
Unexecuted instantiation: tag.c:git_fs_path_is_valid
Unexecuted instantiation: smart_protocol.c:git_fs_path_is_valid
Unexecuted instantiation: tree.c:git_fs_path_is_valid
Unexecuted instantiation: worktree.c:git_fs_path_is_valid
Unexecuted instantiation: filebuf.c:git_fs_path_is_valid
Unexecuted instantiation: fs_path.c:git_fs_path_is_valid
Unexecuted instantiation: futils.c:git_fs_path_is_valid
Unexecuted instantiation: posix.c:git_fs_path_is_valid
Unexecuted instantiation: attr.c:git_fs_path_is_valid
Unexecuted instantiation: attr_file.c:git_fs_path_is_valid
Unexecuted instantiation: attrcache.c:git_fs_path_is_valid
Unexecuted instantiation: blob.c:git_fs_path_is_valid
Unexecuted instantiation: branch.c:git_fs_path_is_valid
Unexecuted instantiation: cache.c:git_fs_path_is_valid
Unexecuted instantiation: checkout.c:git_fs_path_is_valid
Unexecuted instantiation: clone.c:git_fs_path_is_valid
Unexecuted instantiation: commit.c:git_fs_path_is_valid
Unexecuted instantiation: commit_graph.c:git_fs_path_is_valid
Unexecuted instantiation: commit_list.c:git_fs_path_is_valid
Unexecuted instantiation: config.c:git_fs_path_is_valid
Unexecuted instantiation: config_cache.c:git_fs_path_is_valid
Unexecuted instantiation: config_file.c:git_fs_path_is_valid
Unexecuted instantiation: config_list.c:git_fs_path_is_valid
Unexecuted instantiation: config_parse.c:git_fs_path_is_valid
Unexecuted instantiation: config_snapshot.c:git_fs_path_is_valid
Unexecuted instantiation: delta.c:git_fs_path_is_valid
Unexecuted instantiation: diff.c:git_fs_path_is_valid
Unexecuted instantiation: diff_driver.c:git_fs_path_is_valid
Unexecuted instantiation: diff_generate.c:git_fs_path_is_valid
Unexecuted instantiation: diff_print.c:git_fs_path_is_valid
Unexecuted instantiation: diff_tform.c:git_fs_path_is_valid
Unexecuted instantiation: email.c:git_fs_path_is_valid
Unexecuted instantiation: filter.c:git_fs_path_is_valid
Unexecuted instantiation: grafts.c:git_fs_path_is_valid
Unexecuted instantiation: hashsig.c:git_fs_path_is_valid
Unexecuted instantiation: ident.c:git_fs_path_is_valid
Unexecuted instantiation: index.c:git_fs_path_is_valid
Unexecuted instantiation: iterator.c:git_fs_path_is_valid
Unexecuted instantiation: mailmap.c:git_fs_path_is_valid
Unexecuted instantiation: merge.c:git_fs_path_is_valid
Unexecuted instantiation: midx.c:git_fs_path_is_valid
Unexecuted instantiation: patch.c:git_fs_path_is_valid
Unexecuted instantiation: patch_generate.c:git_fs_path_is_valid
Unexecuted instantiation: path.c:git_fs_path_is_valid
Unexecuted instantiation: pathspec.c:git_fs_path_is_valid
Unexecuted instantiation: push.c:git_fs_path_is_valid
Unexecuted instantiation: refdb.c:git_fs_path_is_valid
Unexecuted instantiation: refdb_fs.c:git_fs_path_is_valid
Unexecuted instantiation: reflog.c:git_fs_path_is_valid
Unexecuted instantiation: refs.c:git_fs_path_is_valid
Unexecuted instantiation: remote.c:git_fs_path_is_valid
Unexecuted instantiation: signature.c:git_fs_path_is_valid
Unexecuted instantiation: transaction.c:git_fs_path_is_valid
Unexecuted instantiation: transport.c:git_fs_path_is_valid
Unexecuted instantiation: local.c:git_fs_path_is_valid
Unexecuted instantiation: tree-cache.c:git_fs_path_is_valid
Unexecuted instantiation: sortedcache.c:git_fs_path_is_valid
Unexecuted instantiation: crlf.c:git_fs_path_is_valid
Unexecuted instantiation: diff_file.c:git_fs_path_is_valid
Unexecuted instantiation: diff_stats.c:git_fs_path_is_valid
Unexecuted instantiation: diff_xdiff.c:git_fs_path_is_valid
Unexecuted instantiation: fetch.c:git_fs_path_is_valid
Unexecuted instantiation: fetchhead.c:git_fs_path_is_valid
Unexecuted instantiation: graph.c:git_fs_path_is_valid
Unexecuted instantiation: ignore.c:git_fs_path_is_valid
699
700
/** Validate a filesystem path in a `git_str`. */
701
GIT_INLINE(bool) git_fs_path_str_is_valid(
702
  const git_str *path,
703
  unsigned int flags)
704
0
{
705
0
  return git_fs_path_str_is_valid_ext(path, flags, NULL, NULL, NULL, NULL);
706
0
}
Unexecuted instantiation: fuzzer_utils.c:git_fs_path_str_is_valid
Unexecuted instantiation: indexer.c:git_fs_path_str_is_valid
Unexecuted instantiation: libgit2.c:git_fs_path_str_is_valid
Unexecuted instantiation: merge_driver.c:git_fs_path_str_is_valid
Unexecuted instantiation: merge_file.c:git_fs_path_str_is_valid
Unexecuted instantiation: mwindow.c:git_fs_path_str_is_valid
Unexecuted instantiation: object.c:git_fs_path_str_is_valid
Unexecuted instantiation: object_api.c:git_fs_path_str_is_valid
Unexecuted instantiation: odb.c:git_fs_path_str_is_valid
Unexecuted instantiation: odb_loose.c:git_fs_path_str_is_valid
Unexecuted instantiation: odb_mempack.c:git_fs_path_str_is_valid
Unexecuted instantiation: odb_pack.c:git_fs_path_str_is_valid
Unexecuted instantiation: oid.c:git_fs_path_str_is_valid
Unexecuted instantiation: pack-objects.c:git_fs_path_str_is_valid
Unexecuted instantiation: pack.c:git_fs_path_str_is_valid
Unexecuted instantiation: repository.c:git_fs_path_str_is_valid
Unexecuted instantiation: revparse.c:git_fs_path_str_is_valid
Unexecuted instantiation: revwalk.c:git_fs_path_str_is_valid
Unexecuted instantiation: settings.c:git_fs_path_str_is_valid
Unexecuted instantiation: submodule.c:git_fs_path_str_is_valid
Unexecuted instantiation: sysdir.c:git_fs_path_str_is_valid
Unexecuted instantiation: tag.c:git_fs_path_str_is_valid
Unexecuted instantiation: smart_protocol.c:git_fs_path_str_is_valid
Unexecuted instantiation: tree.c:git_fs_path_str_is_valid
Unexecuted instantiation: worktree.c:git_fs_path_str_is_valid
Unexecuted instantiation: filebuf.c:git_fs_path_str_is_valid
Unexecuted instantiation: fs_path.c:git_fs_path_str_is_valid
Unexecuted instantiation: futils.c:git_fs_path_str_is_valid
Unexecuted instantiation: posix.c:git_fs_path_str_is_valid
Unexecuted instantiation: attr.c:git_fs_path_str_is_valid
Unexecuted instantiation: attr_file.c:git_fs_path_str_is_valid
Unexecuted instantiation: attrcache.c:git_fs_path_str_is_valid
Unexecuted instantiation: blob.c:git_fs_path_str_is_valid
Unexecuted instantiation: branch.c:git_fs_path_str_is_valid
Unexecuted instantiation: cache.c:git_fs_path_str_is_valid
Unexecuted instantiation: checkout.c:git_fs_path_str_is_valid
Unexecuted instantiation: clone.c:git_fs_path_str_is_valid
Unexecuted instantiation: commit.c:git_fs_path_str_is_valid
Unexecuted instantiation: commit_graph.c:git_fs_path_str_is_valid
Unexecuted instantiation: commit_list.c:git_fs_path_str_is_valid
Unexecuted instantiation: config.c:git_fs_path_str_is_valid
Unexecuted instantiation: config_cache.c:git_fs_path_str_is_valid
Unexecuted instantiation: config_file.c:git_fs_path_str_is_valid
Unexecuted instantiation: config_list.c:git_fs_path_str_is_valid
Unexecuted instantiation: config_parse.c:git_fs_path_str_is_valid
Unexecuted instantiation: config_snapshot.c:git_fs_path_str_is_valid
Unexecuted instantiation: delta.c:git_fs_path_str_is_valid
Unexecuted instantiation: diff.c:git_fs_path_str_is_valid
Unexecuted instantiation: diff_driver.c:git_fs_path_str_is_valid
Unexecuted instantiation: diff_generate.c:git_fs_path_str_is_valid
Unexecuted instantiation: diff_print.c:git_fs_path_str_is_valid
Unexecuted instantiation: diff_tform.c:git_fs_path_str_is_valid
Unexecuted instantiation: email.c:git_fs_path_str_is_valid
Unexecuted instantiation: filter.c:git_fs_path_str_is_valid
Unexecuted instantiation: grafts.c:git_fs_path_str_is_valid
Unexecuted instantiation: hashsig.c:git_fs_path_str_is_valid
Unexecuted instantiation: ident.c:git_fs_path_str_is_valid
Unexecuted instantiation: index.c:git_fs_path_str_is_valid
Unexecuted instantiation: iterator.c:git_fs_path_str_is_valid
Unexecuted instantiation: mailmap.c:git_fs_path_str_is_valid
Unexecuted instantiation: merge.c:git_fs_path_str_is_valid
Unexecuted instantiation: midx.c:git_fs_path_str_is_valid
Unexecuted instantiation: patch.c:git_fs_path_str_is_valid
Unexecuted instantiation: patch_generate.c:git_fs_path_str_is_valid
Unexecuted instantiation: path.c:git_fs_path_str_is_valid
Unexecuted instantiation: pathspec.c:git_fs_path_str_is_valid
Unexecuted instantiation: push.c:git_fs_path_str_is_valid
Unexecuted instantiation: refdb.c:git_fs_path_str_is_valid
Unexecuted instantiation: refdb_fs.c:git_fs_path_str_is_valid
Unexecuted instantiation: reflog.c:git_fs_path_str_is_valid
Unexecuted instantiation: refs.c:git_fs_path_str_is_valid
Unexecuted instantiation: remote.c:git_fs_path_str_is_valid
Unexecuted instantiation: signature.c:git_fs_path_str_is_valid
Unexecuted instantiation: transaction.c:git_fs_path_str_is_valid
Unexecuted instantiation: transport.c:git_fs_path_str_is_valid
Unexecuted instantiation: local.c:git_fs_path_str_is_valid
Unexecuted instantiation: tree-cache.c:git_fs_path_str_is_valid
Unexecuted instantiation: sortedcache.c:git_fs_path_str_is_valid
Unexecuted instantiation: crlf.c:git_fs_path_str_is_valid
Unexecuted instantiation: diff_file.c:git_fs_path_str_is_valid
Unexecuted instantiation: diff_stats.c:git_fs_path_str_is_valid
Unexecuted instantiation: diff_xdiff.c:git_fs_path_str_is_valid
Unexecuted instantiation: fetch.c:git_fs_path_str_is_valid
Unexecuted instantiation: fetchhead.c:git_fs_path_str_is_valid
Unexecuted instantiation: graph.c:git_fs_path_str_is_valid
Unexecuted instantiation: ignore.c:git_fs_path_str_is_valid
707
708
extern int git_fs_path_validate_str_length_with_suffix(
709
  git_str *path,
710
  size_t suffix_len);
711
712
/**
713
 * Validate an on-disk path, taking into account that it will have a
714
 * suffix appended (eg, `.lock`).
715
 */
716
GIT_INLINE(int) git_fs_path_validate_filesystem_with_suffix(
717
  const char *path,
718
  size_t path_len,
719
  size_t suffix_len)
720
0
{
721
0
#ifdef GIT_WIN32
722
0
  size_t path_chars, total_chars;
723
0
724
0
  path_chars = git_utf8_char_length(path, path_len);
725
0
726
0
  if (GIT_ADD_SIZET_OVERFLOW(&total_chars, path_chars, suffix_len) ||
727
0
      total_chars > MAX_PATH) {
728
0
    git_error_set(GIT_ERROR_FILESYSTEM, "path too long: '%s'", path);
729
0
    return -1;
730
0
  }
731
0
  return 0;
732
0
#else
733
0
  GIT_UNUSED(path);
734
0
  GIT_UNUSED(path_len);
735
0
  GIT_UNUSED(suffix_len);
736
0
  return 0;
737
0
#endif
738
0
}
Unexecuted instantiation: fuzzer_utils.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: indexer.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: libgit2.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: merge_driver.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: merge_file.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: mwindow.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: object.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: object_api.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: odb.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: odb_loose.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: odb_mempack.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: odb_pack.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: oid.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: pack-objects.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: pack.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: repository.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: revparse.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: revwalk.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: settings.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: submodule.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: sysdir.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: tag.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: smart_protocol.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: tree.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: worktree.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: filebuf.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: fs_path.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: futils.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: posix.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: attr.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: attr_file.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: attrcache.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: blob.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: branch.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: cache.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: checkout.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: clone.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: commit.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: commit_graph.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: commit_list.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: config.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: config_cache.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: config_file.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: config_list.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: config_parse.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: config_snapshot.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: delta.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: diff.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: diff_driver.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: diff_generate.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: diff_print.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: diff_tform.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: email.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: filter.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: grafts.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: hashsig.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: ident.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: index.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: iterator.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: mailmap.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: merge.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: midx.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: patch.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: patch_generate.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: path.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: pathspec.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: push.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: refdb.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: refdb_fs.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: reflog.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: refs.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: remote.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: signature.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: transaction.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: transport.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: local.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: tree-cache.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: sortedcache.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: crlf.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: diff_file.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: diff_stats.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: diff_xdiff.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: fetch.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: fetchhead.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: graph.c:git_fs_path_validate_filesystem_with_suffix
Unexecuted instantiation: ignore.c:git_fs_path_validate_filesystem_with_suffix
739
740
/**
741
 * Validate an path on the filesystem.  This ensures that the given
742
 * path is valid for the operating system/platform; for example, this
743
 * will ensure that the given absolute path is smaller than MAX_PATH on
744
 * Windows.
745
 *
746
 * For paths within the working directory, you should use ensure that
747
 * `core.longpaths` is obeyed.  Use `git_fs_path_validate_workdir`.
748
 */
749
GIT_INLINE(int) git_fs_path_validate_filesystem(
750
  const char *path,
751
  size_t path_len)
752
0
{
753
0
  return git_fs_path_validate_filesystem_with_suffix(path, path_len, 0);
754
0
}
Unexecuted instantiation: fuzzer_utils.c:git_fs_path_validate_filesystem
Unexecuted instantiation: indexer.c:git_fs_path_validate_filesystem
Unexecuted instantiation: libgit2.c:git_fs_path_validate_filesystem
Unexecuted instantiation: merge_driver.c:git_fs_path_validate_filesystem
Unexecuted instantiation: merge_file.c:git_fs_path_validate_filesystem
Unexecuted instantiation: mwindow.c:git_fs_path_validate_filesystem
Unexecuted instantiation: object.c:git_fs_path_validate_filesystem
Unexecuted instantiation: object_api.c:git_fs_path_validate_filesystem
Unexecuted instantiation: odb.c:git_fs_path_validate_filesystem
Unexecuted instantiation: odb_loose.c:git_fs_path_validate_filesystem
Unexecuted instantiation: odb_mempack.c:git_fs_path_validate_filesystem
Unexecuted instantiation: odb_pack.c:git_fs_path_validate_filesystem
Unexecuted instantiation: oid.c:git_fs_path_validate_filesystem
Unexecuted instantiation: pack-objects.c:git_fs_path_validate_filesystem
Unexecuted instantiation: pack.c:git_fs_path_validate_filesystem
Unexecuted instantiation: repository.c:git_fs_path_validate_filesystem
Unexecuted instantiation: revparse.c:git_fs_path_validate_filesystem
Unexecuted instantiation: revwalk.c:git_fs_path_validate_filesystem
Unexecuted instantiation: settings.c:git_fs_path_validate_filesystem
Unexecuted instantiation: submodule.c:git_fs_path_validate_filesystem
Unexecuted instantiation: sysdir.c:git_fs_path_validate_filesystem
Unexecuted instantiation: tag.c:git_fs_path_validate_filesystem
Unexecuted instantiation: smart_protocol.c:git_fs_path_validate_filesystem
Unexecuted instantiation: tree.c:git_fs_path_validate_filesystem
Unexecuted instantiation: worktree.c:git_fs_path_validate_filesystem
Unexecuted instantiation: filebuf.c:git_fs_path_validate_filesystem
Unexecuted instantiation: fs_path.c:git_fs_path_validate_filesystem
Unexecuted instantiation: futils.c:git_fs_path_validate_filesystem
Unexecuted instantiation: posix.c:git_fs_path_validate_filesystem
Unexecuted instantiation: attr.c:git_fs_path_validate_filesystem
Unexecuted instantiation: attr_file.c:git_fs_path_validate_filesystem
Unexecuted instantiation: attrcache.c:git_fs_path_validate_filesystem
Unexecuted instantiation: blob.c:git_fs_path_validate_filesystem
Unexecuted instantiation: branch.c:git_fs_path_validate_filesystem
Unexecuted instantiation: cache.c:git_fs_path_validate_filesystem
Unexecuted instantiation: checkout.c:git_fs_path_validate_filesystem
Unexecuted instantiation: clone.c:git_fs_path_validate_filesystem
Unexecuted instantiation: commit.c:git_fs_path_validate_filesystem
Unexecuted instantiation: commit_graph.c:git_fs_path_validate_filesystem
Unexecuted instantiation: commit_list.c:git_fs_path_validate_filesystem
Unexecuted instantiation: config.c:git_fs_path_validate_filesystem
Unexecuted instantiation: config_cache.c:git_fs_path_validate_filesystem
Unexecuted instantiation: config_file.c:git_fs_path_validate_filesystem
Unexecuted instantiation: config_list.c:git_fs_path_validate_filesystem
Unexecuted instantiation: config_parse.c:git_fs_path_validate_filesystem
Unexecuted instantiation: config_snapshot.c:git_fs_path_validate_filesystem
Unexecuted instantiation: delta.c:git_fs_path_validate_filesystem
Unexecuted instantiation: diff.c:git_fs_path_validate_filesystem
Unexecuted instantiation: diff_driver.c:git_fs_path_validate_filesystem
Unexecuted instantiation: diff_generate.c:git_fs_path_validate_filesystem
Unexecuted instantiation: diff_print.c:git_fs_path_validate_filesystem
Unexecuted instantiation: diff_tform.c:git_fs_path_validate_filesystem
Unexecuted instantiation: email.c:git_fs_path_validate_filesystem
Unexecuted instantiation: filter.c:git_fs_path_validate_filesystem
Unexecuted instantiation: grafts.c:git_fs_path_validate_filesystem
Unexecuted instantiation: hashsig.c:git_fs_path_validate_filesystem
Unexecuted instantiation: ident.c:git_fs_path_validate_filesystem
Unexecuted instantiation: index.c:git_fs_path_validate_filesystem
Unexecuted instantiation: iterator.c:git_fs_path_validate_filesystem
Unexecuted instantiation: mailmap.c:git_fs_path_validate_filesystem
Unexecuted instantiation: merge.c:git_fs_path_validate_filesystem
Unexecuted instantiation: midx.c:git_fs_path_validate_filesystem
Unexecuted instantiation: patch.c:git_fs_path_validate_filesystem
Unexecuted instantiation: patch_generate.c:git_fs_path_validate_filesystem
Unexecuted instantiation: path.c:git_fs_path_validate_filesystem
Unexecuted instantiation: pathspec.c:git_fs_path_validate_filesystem
Unexecuted instantiation: push.c:git_fs_path_validate_filesystem
Unexecuted instantiation: refdb.c:git_fs_path_validate_filesystem
Unexecuted instantiation: refdb_fs.c:git_fs_path_validate_filesystem
Unexecuted instantiation: reflog.c:git_fs_path_validate_filesystem
Unexecuted instantiation: refs.c:git_fs_path_validate_filesystem
Unexecuted instantiation: remote.c:git_fs_path_validate_filesystem
Unexecuted instantiation: signature.c:git_fs_path_validate_filesystem
Unexecuted instantiation: transaction.c:git_fs_path_validate_filesystem
Unexecuted instantiation: transport.c:git_fs_path_validate_filesystem
Unexecuted instantiation: local.c:git_fs_path_validate_filesystem
Unexecuted instantiation: tree-cache.c:git_fs_path_validate_filesystem
Unexecuted instantiation: sortedcache.c:git_fs_path_validate_filesystem
Unexecuted instantiation: crlf.c:git_fs_path_validate_filesystem
Unexecuted instantiation: diff_file.c:git_fs_path_validate_filesystem
Unexecuted instantiation: diff_stats.c:git_fs_path_validate_filesystem
Unexecuted instantiation: diff_xdiff.c:git_fs_path_validate_filesystem
Unexecuted instantiation: fetch.c:git_fs_path_validate_filesystem
Unexecuted instantiation: fetchhead.c:git_fs_path_validate_filesystem
Unexecuted instantiation: graph.c:git_fs_path_validate_filesystem
Unexecuted instantiation: ignore.c:git_fs_path_validate_filesystem
755
756
/**
757
 * Convert any backslashes into slashes
758
 */
759
int git_fs_path_normalize_slashes(git_str *out, const char *path);
760
761
bool git_fs_path_supports_symlinks(const char *dir);
762
763
typedef enum {
764
  GIT_FS_PATH_OWNER_NONE = 0,
765
766
  /** The file must be owned by the current user. */
767
  GIT_FS_PATH_OWNER_CURRENT_USER = (1 << 0),
768
769
  /** The file must be owned by the system account. */
770
  GIT_FS_PATH_OWNER_ADMINISTRATOR = (1 << 1),
771
772
  /**
773
   * The file may be owned by a system account if the current
774
   * user is in an administrator group. Windows only; this is
775
   * a noop on non-Windows systems.
776
   */
777
  GIT_FS_PATH_USER_IS_ADMINISTRATOR = (1 << 2),
778
779
  /**
780
   * The file is owned by the current user, who is running `sudo`.
781
   */
782
  GIT_FS_PATH_OWNER_RUNNING_SUDO = (1 << 3),
783
784
  /** The file may be owned by another user. */
785
  GIT_FS_PATH_OWNER_OTHER = (1 << 4)
786
} git_fs_path_owner_t;
787
788
/**
789
 * Sets the mock ownership for files; subsequent calls to
790
 * `git_fs_path_owner_is_*` functions will return this data until
791
 * cleared with `GIT_FS_PATH_OWNER_NONE`.
792
 */
793
void git_fs_path__set_owner(git_fs_path_owner_t owner);
794
795
/** Verify that the file in question is owned by the given owner. */
796
int git_fs_path_owner_is(
797
  bool *out,
798
  const char *path,
799
  git_fs_path_owner_t owner_type);
800
801
/**
802
 * Verify that the file in question is owned by an administrator or system
803
 * account.
804
 */
805
int git_fs_path_owner_is_system(bool *out, const char *path);
806
807
/**
808
 * Verify that the file in question is owned by the current user;
809
 */
810
811
int git_fs_path_owner_is_current_user(bool *out, const char *path);
812
813
/**
814
 * Search the current PATH for the given executable, returning the full
815
 * path if it is found.
816
 */
817
int git_fs_path_find_executable(git_str *fullpath, const char *executable);
818
819
#endif