diff options
author | Johannes Schindelin <johannes.schindelin@gmx.de> | 2019-12-21 23:05:01 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2019-12-22 01:09:07 +0100 |
commit | 4dc42c6c1867a52e22f1f04a1a247b5a7538b8af (patch) | |
tree | 2198d9e1995d36e5448de2dcf2c9063563f03803 /compat/mingw.h | |
parent | mingw: short-circuit the conversion of `/dev/null` to UTF-16 (diff) | |
download | git-4dc42c6c1867a52e22f1f04a1a247b5a7538b8af.tar.xz git-4dc42c6c1867a52e22f1f04a1a247b5a7538b8af.zip |
mingw: refuse paths containing reserved names
There are a couple of reserved names that cannot be file names on
Windows, such as `AUX`, `NUL`, etc. For an almost complete list, see
https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file
If one would try to create a directory named `NUL`, it would actually
"succeed", i.e. the call would return success, but nothing would be
created.
Worse, even adding a file extension to the reserved name does not make
it a valid file name. To understand the rationale behind that behavior,
see https://devblogs.microsoft.com/oldnewthing/20031022-00/?p=42073
Let's just disallow them all.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'compat/mingw.h')
-rw-r--r-- | compat/mingw.h | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/compat/mingw.h b/compat/mingw.h index 04ca731a6b..ebc1e6a773 100644 --- a/compat/mingw.h +++ b/compat/mingw.h @@ -461,10 +461,17 @@ char *mingw_query_user_email(void); * * - contain any of the reserved characters, e.g. `:`, `;`, `*`, etc * + * - correspond to reserved names (such as `AUX`, `PRN`, etc) + * + * The `allow_literal_nul` parameter controls whether the path `NUL` should + * be considered valid (this makes sense e.g. before opening files, as it is + * perfectly legitimate to open `NUL` on Windows, just as it is to open + * `/dev/null` on Unix/Linux). + * * Returns 1 upon success, otherwise 0. */ -int is_valid_win32_path(const char *path); -#define is_valid_path(path) is_valid_win32_path(path) +int is_valid_win32_path(const char *path, int allow_literal_nul); +#define is_valid_path(path) is_valid_win32_path(path, 0) /** * Converts UTF-8 encoded string to UTF-16LE. |