Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refuse to write to reserved filenames #2440

Merged
merged 3 commits into from
Dec 26, 2019

Conversation

dscho
Copy link
Member

@dscho dscho commented Dec 19, 2019

This is a companion PR to gitgitgadget#496 (including a merge commit needed to sort out merge conflicts with the core.longPaths feature).

On Windows, for historical reasons, file names such as aux.c, nul.txt are not allowed. For aux.c, attempts to write such a file will result in an obscure error, for nul.txt the call will succeed but no such file will appear, ever, instead the effect will be equivalent to writing to /dev/null on Linux/Unix.

Let's help users by refusing to create such files altogether, with an informative error message.

This addresses #679 and supersedes #686

In the next commit, we want to disallow accessing any path that contains
any segment that is equivalent to `NUL`. In particular, we want to
disallow accessing `NUL` (e.g. to prevent any repository from being
checked out that contains a file called `NUL`, as that is not a valid
file name on Windows).

However, there are legitimate use cases within Git itself to write to
the Null device. As Git is really a Linux project, it does not abstract
that idea, though, but instead uses `/dev/null` to describe this
intention.

So let's side-step the validation _specifically_ in the case that we
want to write to (or read from) `/dev/null`, via a dedicated short-cut
in the code that skips the call to `validate_win32_path()`.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
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>
This topic branch refuses to create files with reserved file names, such
as `aux.c` or `nul.txt`.

This addresses git-for-windows#679.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
@dscho dscho merged commit baa8b8a into git-for-windows:master Dec 26, 2019
@dscho dscho added this to the Next release milestone Dec 26, 2019
dscho added a commit to dscho/git that referenced this pull request Dec 27, 2019
…enames-gfw

 Refuse to write to reserved filenames
git-for-windows-ci pushed a commit that referenced this pull request Dec 29, 2019
dscho added a commit that referenced this pull request Dec 29, 2019
dscho added a commit that referenced this pull request Jan 4, 2020
@dscho dscho deleted the mingw-reserved-filenames-gfw branch January 6, 2020 09:12
dscho added a commit that referenced this pull request Jan 13, 2020
git-for-windows-ci pushed a commit that referenced this pull request Jan 16, 2020
git-for-windows-ci pushed a commit that referenced this pull request Jan 17, 2020
git-for-windows-ci pushed a commit that referenced this pull request Jan 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant