Skip to content

Commit f578006

Browse files
dschoGit for Windows Build Agent
authored andcommitted
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 cdd6153 commit f578006

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
@@ -3230,12 +3230,14 @@ int is_valid_win32_path(const char *path, int allow_literal_nul)
32303230
continue;
32313231
}
32323232
break;
3233-
case 'c': case 'C': /* COM<N>, CON, CONIN$, CONOUT$ */
3233+
case 'c': case 'C':
3234+
/* COM1 ... COM9, CON, CONIN$, CONOUT$ */
32343235
if ((c = path[++i]) != 'o' && c != 'O')
32353236
goto not_a_reserved_name;
32363237
c = path[++i];
3237-
if (c == 'm' || c == 'M') { /* COM<N> */
3238-
if (!isdigit(path[++i]))
3238+
if (c == 'm' || c == 'M') { /* COM1 ... COM9 */
3239+
c = path[++i];
3240+
if (c < '1' || c > '9')
32393241
goto not_a_reserved_name;
32403242
} else if (c == 'n' || c == 'N') { /* CON */
32413243
c = path[i + 1];

t/t0060-path-utils.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,7 @@ test_expect_success MINGW 'is_valid_path() on Windows' '
472472
C:\\git \
473473
comm \
474474
conout.c \
475+
com0.c \
475476
lptN \
476477
\
477478
--not \
@@ -484,6 +485,7 @@ test_expect_success MINGW 'is_valid_path() on Windows' '
484485
"AUX.c" \
485486
"abc/conOut\$ .xyz/test" \
486487
lpt8 \
488+
com9.c \
487489
"lpt*" \
488490
Nul \
489491
"PRN./abc"

0 commit comments

Comments
 (0)