Skip to content

Commit 95d2bdd

Browse files
dschoGit for Windows Build Agent
authored and
Git for Windows Build Agent
committed
mingw: do not treat COM0 as a reserved file name
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 <[email protected]>
1 parent 2405549 commit 95d2bdd

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

compat/mingw.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2581,12 +2581,14 @@ int is_valid_win32_path(const char *path, int allow_literal_nul)
25812581
continue;
25822582
}
25832583
break;
2584-
case 'c': case 'C': /* COM<N>, CON, CONIN$, CONOUT$ */
2584+
case 'c': case 'C':
2585+
/* COM1 ... COM9, CON, CONIN$, CONOUT$ */
25852586
if ((c = path[++i]) != 'o' && c != 'O')
25862587
goto not_a_reserved_name;
25872588
c = path[++i];
2588-
if (c == 'm' || c == 'M') { /* COM<N> */
2589-
if (!isdigit(path[++i]))
2589+
if (c == 'm' || c == 'M') { /* COM1 ... COM9 */
2590+
c = path[++i];
2591+
if (c < '1' || c > '9')
25902592
goto not_a_reserved_name;
25912593
} else if (c == 'n' || c == 'N') { /* CON */
25922594
c = path[i + 1];

t/t0060-path-utils.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@ test_expect_success MINGW 'is_valid_path() on Windows' '
476476
C:\\git \
477477
comm \
478478
conout.c \
479+
com0.c \
479480
lptN \
480481
\
481482
--not \
@@ -488,6 +489,7 @@ test_expect_success MINGW 'is_valid_path() on Windows' '
488489
"AUX.c" \
489490
"abc/conOut\$ .xyz/test" \
490491
lpt8 \
492+
com9.c \
491493
"lpt*" \
492494
Nul \
493495
"PRN./abc"

0 commit comments

Comments
 (0)