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 on Windows #496

Closed
wants to merge 2 commits into from

Conversation

dscho
Copy link
Member

@dscho dscho commented Dec 19, 2019

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.

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>
@dscho
Copy link
Member Author

dscho commented Dec 21, 2019

/submit

@gitgitgadget
Copy link

gitgitgadget bot commented Dec 21, 2019

@gitgitgadget
Copy link

gitgitgadget bot commented Dec 22, 2019

This branch is now known as js/mingw-reserved-filenames.

@gitgitgadget
Copy link

gitgitgadget bot commented Dec 22, 2019

This patch series was integrated into pu via git@19df3e0.

@gitgitgadget gitgitgadget bot added the pu label Dec 22, 2019
@gitgitgadget
Copy link

gitgitgadget bot commented Dec 25, 2019

This patch series was integrated into pu via git@29cfef7.

@gitgitgadget
Copy link

gitgitgadget bot commented Dec 26, 2019

This patch series was integrated into pu via git@56a7159.

@gitgitgadget
Copy link

gitgitgadget bot commented Dec 28, 2019

This patch series was integrated into pu via git@74542f4.

@gitgitgadget
Copy link

gitgitgadget bot commented Dec 30, 2019

This patch series was integrated into pu via git@c8499a2.

@gitgitgadget
Copy link

gitgitgadget bot commented Dec 30, 2019

This patch series was integrated into next via git@5b814fd.

@gitgitgadget gitgitgadget bot added the next label Dec 30, 2019
@gitgitgadget
Copy link

gitgitgadget bot commented Jan 2, 2020

This patch series was integrated into pu via git@b612456.

@gitgitgadget
Copy link

gitgitgadget bot commented Jan 3, 2020

This patch series was integrated into pu via git@13432fc.

@gitgitgadget
Copy link

gitgitgadget bot commented Jan 3, 2020

This patch series was integrated into next via git@13432fc.

@gitgitgadget
Copy link

gitgitgadget bot commented Jan 3, 2020

This patch series was integrated into master via git@13432fc.

@gitgitgadget gitgitgadget bot added the master label Jan 3, 2020
@gitgitgadget gitgitgadget bot closed this Jan 3, 2020
@gitgitgadget
Copy link

gitgitgadget bot commented Jan 3, 2020

Closed via 13432fc.

@dscho dscho deleted the mingw-reserved-filenames branch January 3, 2020 19:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant