]> granicus.if.org Git - transmission/commitdiff
Add unit tests uncovering improper UNC paths resolution
authorMike Gelfand <mikedld@mikedld.com>
Wed, 24 Jan 2018 20:06:21 +0000 (23:06 +0300)
committerMike Gelfand <mikedld@mikedld.com>
Wed, 24 Jan 2018 20:12:17 +0000 (23:12 +0300)
While resolved paths always contain the `\\?\` prefix, it's not always
correct to strip only those 4 chars. In case of UNC paths, the prefix
is actually a bit longer (`\\?\UNC\`) and needs to be replaced with `\\`
instead.

Failing to do so results in invalid paths, e.g. `\\Host\Share\File` becomes
`UNC\Host\Share\File` which totally wrong.

libtransmission/file-test.c

index 25aafed30419b938fe02b0f8a7ec05c2a6016a25..02dfd5ff4211da9e4da640f6e209eee39c3d981b 100644 (file)
@@ -635,6 +635,29 @@ static int test_path_resolve(void)
     tr_free(path2);
     tr_free(path1);
 
+#ifdef _WIN32
+
+    {
+        char* tmp;
+
+        tmp = tr_sys_path_resolve("\\\\127.0.0.1\\NonExistent", &err);
+        check_str(tmp, ==, NULL);
+        check_ptr(err, !=, NULL);
+        tr_error_clear(&err);
+
+        tmp = tr_sys_path_resolve("\\\\127.0.0.1\\ADMIN$\\NonExistent", &err);
+        check_str(tmp, ==, NULL);
+        check_ptr(err, !=, NULL);
+        tr_error_clear(&err);
+
+        tmp = tr_sys_path_resolve("\\\\127.0.0.1\\ADMIN$\\System32", &err);
+        check_str(tmp, ==, "\\\\127.0.0.1\\ADMIN$\\System32");
+        check_ptr(err, ==, NULL);
+        tr_free(tmp);
+    }
+
+#endif
+
     tr_free(test_dir);
     return 0;
 }