summaryrefslogtreecommitdiff
path: root/src/path.h
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@microsoft.com>2014-11-25 18:13:00 -0500
committerEdward Thomson <ethomson@microsoft.com>2014-12-16 10:08:53 -0600
commita64119e3963fcd358ba914c9e1a81a890666d15a (patch)
treef81788b6b64bc56b84f59da979895078ec93b246 /src/path.h
parent0d388adc86946f3c8cddc2493b470d47a653c4a5 (diff)
downloadlibgit2-a64119e3963fcd358ba914c9e1a81a890666d15a.tar.gz
checkout: disallow bad paths on win32
Disallow: 1. paths with trailing dot 2. paths with trailing space 3. paths with trailing colon 4. paths that are 8.3 short names of .git folders ("GIT~1") 5. paths that are reserved path names (COM1, LPT1, etc). 6. paths with reserved DOS characters (colons, asterisks, etc) These paths would (without \\?\ syntax) be elided to other paths - for example, ".git." would be written as ".git". As a result, writing these paths literally (using \\?\ syntax) makes them hard to operate with from the shell, Windows Explorer or other tools. Disallow these.
Diffstat (limited to 'src/path.h')
-rw-r--r--src/path.h38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/path.h b/src/path.h
index 23d7c2ddb..a97668a98 100644
--- a/src/path.h
+++ b/src/path.h
@@ -462,4 +462,42 @@ extern bool git_path_does_fs_decompose_unicode(const char *root);
extern bool git_path_is_local_file_url(const char *file_url);
extern int git_path_from_url_or_path(git_buf *local_path_out, const char *url_or_path);
+/* Flags to determine path validity in `git_path_isvalid` */
+#define GIT_PATH_REJECT_TRAVERSAL (1 << 0)
+#define GIT_PATH_REJECT_DOT_GIT (1 << 1)
+#define GIT_PATH_REJECT_BACKSLASH (1 << 2)
+#define GIT_PATH_REJECT_TRAILING_DOT (1 << 3)
+#define GIT_PATH_REJECT_TRAILING_SPACE (1 << 4)
+#define GIT_PATH_REJECT_TRAILING_COLON (1 << 5)
+#define GIT_PATH_REJECT_DOS_GIT_SHORTNAME (1 << 6)
+#define GIT_PATH_REJECT_DOS_PATHS (1 << 7)
+#define GIT_PATH_REJECT_NT_CHARS (1 << 8)
+
+#ifdef GIT_WIN32
+# define GIT_PATH_REJECT_DEFAULTS \
+ GIT_PATH_REJECT_TRAVERSAL | \
+ GIT_PATH_REJECT_BACKSLASH | \
+ GIT_PATH_REJECT_TRAILING_DOT | \
+ GIT_PATH_REJECT_TRAILING_SPACE | \
+ GIT_PATH_REJECT_TRAILING_COLON | \
+ GIT_PATH_REJECT_DOS_GIT_SHORTNAME | \
+ GIT_PATH_REJECT_DOS_PATHS | \
+ GIT_PATH_REJECT_NT_CHARS
+#else
+# define GIT_PATH_REJECT_DEFAULTS GIT_PATH_REJECT_TRAVERSAL
+#endif
+
+/*
+ * Determine whether a path is a valid git path or not - this must not contain
+ * a '.' or '..' component, or a component that is ".git" (in any case).
+ *
+ * `repo` is optional. If specified, it will be used to determine the short
+ * path name to reject (if `GIT_PATH_REJECT_DOS_SHORTNAME` is specified),
+ * in addition to the default of "git~1".
+ */
+extern bool git_path_isvalid(
+ git_repository *repo,
+ const char *path,
+ unsigned int flags);
+
#endif