← Commit list

1ac826a1e0

Daniel Stenberg
Daniel Stenberg
2026-09-21
SUCCESS Duration: 385s

Subject

tool_doswin: recognize superscript numbers as reserved

Binary

No binary (build failed)

Architecture & Compiler Flags

Architecture: x86_64-linux-gnu Compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0

—

Build Log

(log yok)

Commit Diff GitHub →

src/tool_doswin.c+35 -7
@@ -272,6 +272,40 @@ static SANITIZEcode msdosify(char ** const sanitized, const char *file_name,
}
#endif /* MSDOS */
+/* return the number of bytes of the reserved prefix, zero if none exists */
+static int prefix_reserved(const char *p)
+{
+ if(curl_strnequal(p, "COM", 3) || curl_strnequal(p, "LPT", 3)) {
+ const uint8_t *up = (const uint8_t *)p;
+ uint8_t super;
+ int len;
+ if(('1' <= p[3]) && (p[3] <= '9'))
+ return 4;
+
+ /* to complicate things, Windows considers superscript 1, 2, 3 to be valid
+ numbers and they can be provided in ISO8859-1 or UTF-8. Avoid either
+ version. */
+ len = (up[3] == 0xc2) ? /* UTF-8 */ 4 : 3;
+ super = up[len];
+
+ switch(super) {
+ case 0xb9: /* superscript '1' */
+ case 0xb2: /* superscript '2' */
+ case 0xb3: /* superscript '3' */
+ return len + 1;
+ }
+ return 0;
+ }
+ else if(curl_strnequal(p, "CON", 3) ||
+ curl_strnequal(p, "PRN", 3) ||
+ curl_strnequal(p, "AUX", 3) ||
+ curl_strnequal(p, "NUL", 3))
+ return 3;
+ else if(curl_strnequal(p, "CLOCK$", 6))
+ return 6;
+ return 0;
+}
+
/*
* Rename file_name if it is a reserved dos device name.
*
@@ -334,13 +368,7 @@ static SANITIZEcode rename_if_reserved_dos(char ** const sanitized,
*/
for(p = buffer; p; p = (p == buffer && buffer != base ? base : NULL)) {
size_t p_len;
- int x = (curl_strnequal(p, "CON", 3) ||
- curl_strnequal(p, "PRN", 3) ||
- curl_strnequal(p, "AUX", 3) ||
- curl_strnequal(p, "NUL", 3)) ? 3 :
- curl_strnequal(p, "CLOCK$", 6) ? 6 :
- (curl_strnequal(p, "COM", 3) || curl_strnequal(p, "LPT", 3)) ?
- (('1' <= p[3] && p[3] <= '9') ? 4 : 3) : 0;
+ int x = prefix_reserved(p);
if(!x)
continue;
tests/tunit/tool1604.c+48 -0
@@ -126,6 +126,15 @@ static CURLcode test_tool1604(const char *arg)
{ "com1", 0,
"_com1", SANITIZE_ERR_OK
},
+ { "com4", 0,
+ "_com4", SANITIZE_ERR_OK
+ },
+ { "com6", 0,
+ "_com6", SANITIZE_ERR_OK
+ },
+ { "com9", 0,
+ "_com9", SANITIZE_ERR_OK
+ },
{ "com1", SANITIZE_ALLOW_RESERVED,
"com1", SANITIZE_ERR_OK
},
@@ -170,6 +179,45 @@ static CURLcode test_tool1604(const char *arg)
{ "COM56", 0,
"COM56", SANITIZE_ERR_OK
},
+ { "COM\xc2\xb9", 0,
+ "_COM\xc2\xb9", SANITIZE_ERR_OK
+ },
+ { "COM\xc2\xb2", 0,
+ "_COM\xc2\xb2", SANITIZE_ERR_OK
+ },
+ { "COM\xc2\xb3", 0,
+ "_COM\xc2\xb3", SANITIZE_ERR_OK
+ },
+ { "COM\xb9", 0,
+ "_COM\xb9", SANITIZE_ERR_OK
+ },
+ { "COM\xb2", 0,
+ "_COM\xb2", SANITIZE_ERR_OK
+ },
+ { "COM\xb3", 0,
+ "_COM\xb3", SANITIZE_ERR_OK
+ },
+ { "lpt\xc2\xb9", 0,
+ "_lpt\xc2\xb9", SANITIZE_ERR_OK
+ },
+ { "lpt\xc2\xb2", 0,
+ "_lpt\xc2\xb2", SANITIZE_ERR_OK
+ },
+ { "lpt\xc2\xb3", 0,
+ "_lpt\xc2\xb3", SANITIZE_ERR_OK
+ },
+ { "lpt\xc2\xb9.txt", 0,
+ "lpt\xc2\xb9_txt", SANITIZE_ERR_OK
+ },
+ { "lpt\xc2\xb2.txt", 0,
+ "lpt\xc2\xb2_txt", SANITIZE_ERR_OK
+ },
+ { "lpt\xc2\xb3.txt", 0,
+ "lpt\xc2\xb3_txt", SANITIZE_ERR_OK
+ },
+ { "COM\xc2\xb3", SANITIZE_ALLOW_RESERVED,
+ "COM\xc2\xb3", SANITIZE_ERR_OK
+ },
{ NULL, 0,
NULL, SANITIZE_ERR_BAD_ARGUMENT
},