@matheusbsbs / matheus-bagliano / commits / b6852e1979
Fork 0

mingw: do not treat `COM0` as a reserved file name

In 4dc42c6c186 (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 https://github.com/git-for-windows/git/issues/2470. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Apr 8, 2020 at 18:06 UTC b6852e19794245566f7c961a434c56ca3b7a883b
2 files changed +7 -3
compat/mingw.c
+5 -3
@@ -2590,12 +2590,14 @@ not_a_reserved_name:
2590 continue;
2591 }
2592 break;
2593 - case 'c': case 'C': /* COM<N>, CON, CONIN$, CONOUT$ */
2593 + case 'c': case 'C':
2594 + /* COM1 ... COM9, CON, CONIN$, CONOUT$ */
2595 if ((c = path[++i]) != 'o' && c != 'O')
2596 goto not_a_reserved_name;
2597 c = path[++i];
2597 - if (c == 'm' || c == 'M') { /* COM<N> */
2598 - if (!isdigit(path[++i]))
2598 + if (c == 'm' || c == 'M') { /* COM1 ... COM9 */
2599 + c = path[++i];
2600 + if (c < '1' || c > '9')
2601 goto not_a_reserved_name;
2602 } else if (c == 'n' || c == 'N') { /* CON */
2603 c = path[i + 1];
t/t0060-path-utils.sh
+2
@@ -476,6 +476,7 @@ test_expect_success MINGW 'is_valid_path() on Windows' '
476 C:\\git \
477 comm \
478 conout.c \
479 + com0.c \
480 lptN \
481 \
482 --not \
@@ -488,6 +489,7 @@ test_expect_success MINGW 'is_valid_path() on Windows' '
489 "AUX.c" \
490 "abc/conOut\$ .xyz/test" \
491 lpt8 \
492 + com9.c \
493 "lpt*" \
494 Nul \
495 "PRN./abc"