diff --git a/src/tool_doswin.c b/src/tool_doswin.c index 8650427ca0525c57caebab2cba6939c74c387d65..aed657a6aefc9b9ee19f03eea8464dc1413d0110 100644 --- a/src/tool_doswin.c +++ b/src/tool_doswin.c @@ -150,9 +150,8 @@ SANITIZEcode sanitize_file_name(char **const sanitized, const char *file_name, if((flags & SANITIZE_ALLOW_PATH)) { #ifndef MSDOS - if((flags & SANITIZE_ALLOW_PATH) && - file_name[0] == '\\' && file_name[1] == '\\') - /* UNC prefixed path, eg \\?\C:\foo */ + if(file_name[0] == '\\' && file_name[1] == '\\') + /* UNC prefixed path \\ (eg \\?\C:\foo) */ max_sanitized_len = 32767-1; else #endif @@ -180,8 +179,16 @@ SANITIZEcode sanitize_file_name(char **const sanitized, const char *file_name, strncpy(target, file_name, len); target[len] = '\0'; +#ifndef MSDOS + if((flags & SANITIZE_ALLOW_PATH) && !strncmp(target, "\\\\?\\", 4)) + /* Skip the literal path prefix \\?\ */ + p = target + 4; + else +#endif + p = target; + /* replace control characters and other banned characters */ - for(p = target; *p; ++p) { + for(; *p; ++p) { const char *banned; if((1 <= *p && *p <= 31) || diff --git a/tests/unit/unit1604.c b/tests/unit/unit1604.c index b4878590236e651e07ae7bb475fc1925931e157a..c61f010dc62fa1d1119036065082ffa5e4cae93e 100644 --- a/tests/unit/unit1604.c +++ b/tests/unit/unit1604.c @@ -110,6 +110,14 @@ UNITTEST_START { "f:/foo", SANITIZE_ALLOW_PATH, "f:/foo", SANITIZE_ERR_OK }, +#ifndef MSDOS + { "\\\\?\\C:\\foo", SANITIZE_ALLOW_PATH, + "\\\\?\\C:\\foo", SANITIZE_ERR_OK + }, + { "\\\\?\\C:\\foo", 0, + "____C__foo", SANITIZE_ERR_OK + }, +#endif { "foo:bar", 0, "foo_bar", SANITIZE_ERR_OK }, @@ -164,6 +172,17 @@ UNITTEST_START { "com1:\\com1", SANITIZE_ALLOW_RESERVED, "com1__com1", SANITIZE_ERR_OK }, +#ifndef MSDOS + { "\\com1", SANITIZE_ALLOW_PATH, + "\\_com1", SANITIZE_ERR_OK + }, + { "\\\\com1", SANITIZE_ALLOW_PATH, + "\\\\com1", SANITIZE_ERR_OK + }, + { "\\\\?\\C:\\com1", SANITIZE_ALLOW_PATH, + "\\\\?\\C:\\com1", SANITIZE_ERR_OK + }, +#endif { "CoM1", 0, "_CoM1", SANITIZE_ERR_OK },