Skip to content

Commit

Permalink
mingw: do not treat COM0 as a reserved file name
Browse files Browse the repository at this point in the history
In 4dc42c6 (mingw: refuse paths containing reserved names,
2019-12-21), we started disallowing file names that are reserved, e.g.
`NUL`, `CONOUT$`, etc.

This included `COM<n>` where `<n>` is a digit. Unfortunately, this
includes `COM0` but only `COM1`, ..., `COM9` are reserved, according to
the official documentation, `COM0` is mentioned in the "NT Namespaces"
section but it is explicitly _omitted_ from the list of reserved names:
https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file#naming-conventions

Tests corroborate this: it is totally possible to write a file called
`com0.c` on Windows 10, but not `com1.c`.

So let's tighten the code to disallow only the reserved `COM<n>` file
names, but to allow `COM0` again.

This fixes #2470.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
  • Loading branch information
dscho authored and Git for Windows Build Agent committed Apr 14, 2020
1 parent 7ffbb22 commit 3944863
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 5 additions & 3 deletions compat/mingw.c
Original file line number Diff line number Diff line change
Expand Up @@ -2581,12 +2581,14 @@ int is_valid_win32_path(const char *path, int allow_literal_nul)
continue;
}
break;
case 'c': case 'C': /* COM<N>, CON, CONIN$, CONOUT$ */
case 'c': case 'C':
/* COM1 ... COM9, CON, CONIN$, CONOUT$ */
if ((c = path[++i]) != 'o' && c != 'O')
goto not_a_reserved_name;
c = path[++i];
if (c == 'm' || c == 'M') { /* COM<N> */
if (!isdigit(path[++i]))
if (c == 'm' || c == 'M') { /* COM1 ... COM9 */
c = path[++i];
if (c < '1' || c > '9')
goto not_a_reserved_name;
} else if (c == 'n' || c == 'N') { /* CON */
c = path[i + 1];
Expand Down
2 changes: 2 additions & 0 deletions t/t0060-path-utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ test_expect_success MINGW 'is_valid_path() on Windows' '
C:\\git \
comm \
conout.c \
com0.c \
lptN \
\
--not \
Expand All @@ -488,6 +489,7 @@ test_expect_success MINGW 'is_valid_path() on Windows' '
"AUX.c" \
"abc/conOut\$ .xyz/test" \
lpt8 \
com9.c \
"lpt*" \
Nul \
"PRN./abc"
Expand Down

0 comments on commit 3944863

Please sign in to comment.