| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 98e399b commit 9cc89f5
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -291,10 +291,16 @@ const win32 = { | |||
| 291 | 291 | j++; | |
| 292 | 292 | } | |
| 293 | 293 | if (j === len || j !== last) { | |
| 294 | - // We matched a UNC root | ||
| 295 | - device = | ||
| 296 | - `\\\\${firstPart}\\${StringPrototypeSlice(path, last, j)}`; | ||
| 297 | - rootEnd = j; | ||
| 294 | + if (firstPart !== '.' && firstPart !== '?') { | ||
| 295 | + // We matched a UNC root | ||
| 296 | + device = | ||
| 297 | + `\\\\${firstPart}\\${StringPrototypeSlice(path, last, j)}`; | ||
| 298 | + rootEnd = j; | ||
| 299 | + } else { | ||
| 300 | + // We matched a device root (e.g. \\\\.\\PHYSICALDRIVE0) | ||
| 301 | + device = `\\\\${firstPart}`; | ||
| 302 | + rootEnd = 4; | ||
| 303 | + } | ||
| 298 | 304 | } | |
| 299 | 305 | } | |
| 300 | 306 | } | |
@@ -404,17 +410,22 @@ const win32 = { | |||
| 404 | 410 | !isPathSeparator(StringPrototypeCharCodeAt(path, j))) { | |
| 405 | 411 | j++; | |
| 406 | 412 | } | |
| 407 | - if (j === len) { | ||
| 408 | - // We matched a UNC root only | ||
| 409 | - // Return the normalized version of the UNC root since there | ||
| 410 | - // is nothing left to process | ||
| 411 | - return `\\\\${firstPart}\\${StringPrototypeSlice(path, last)}\\`; | ||
| 412 | - } | ||
| 413 | - if (j !== last) { | ||
| 414 | - // We matched a UNC root with leftovers | ||
| 415 | - device = | ||
| 416 | - `\\\\${firstPart}\\${StringPrototypeSlice(path, last, j)}`; | ||
| 417 | - rootEnd = j; | ||
| 413 | + if (j === len || j !== last) { | ||
| 414 | + if (firstPart === '.' || firstPart === '?') { | ||
| 415 | + // We matched a device root (e.g. \\\\.\\PHYSICALDRIVE0) | ||
| 416 | + device = `\\\\${firstPart}`; | ||
| 417 | + rootEnd = 4; | ||
| 418 | + } else if (j === len) { | ||
| 419 | + // We matched a UNC root only | ||
| 420 | + // Return the normalized version of the UNC root since there | ||
| 421 | + // is nothing left to process | ||
| 422 | + return `\\\\${firstPart}\\${StringPrototypeSlice(path, last)}\\`; | ||
| 423 | + } else { | ||
| 424 | + // We matched a UNC root with leftovers | ||
| 425 | + device = | ||
| 426 | + `\\\\${firstPart}\\${StringPrototypeSlice(path, last, j)}`; | ||
| 427 | + rootEnd = j; | ||
| 428 | + } | ||
| 418 | 429 | } | |
| 419 | 430 | } | |
| 420 | 431 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -170,9 +170,16 @@ std::string PathResolve(Environment* env, | |||
| 170 | 170 | j++; | |
| 171 | 171 | } | |
| 172 | 172 | if (j == len || j != last) { | |
| 173 | - // We matched a UNC root | ||
| 174 | - device = "\\\\" + firstPart + "\\" + path.substr(last, j - last); | ||
| 175 | - rootEnd = j; | ||
| 173 | + if (firstPart != "." && firstPart != "?") { | ||
| 174 | + // We matched a UNC root | ||
| 175 | + device = | ||
| 176 | + "\\\\" + firstPart + "\\" + path.substr(last, j - last); | ||
| 177 | + rootEnd = j; | ||
| 178 | + } else { | ||
| 179 | + // We matched a device root (e.g. \\\\.\\PHYSICALDRIVE0) | ||
| 180 | + device = "\\\\" + firstPart; | ||
| 181 | + rootEnd = 4; | ||
| 182 | + } | ||
| 176 | 183 | } | |
| 177 | 184 | } | |
| 178 | 185 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -39,6 +39,10 @@ TEST_F(PathTest, PathResolve) { | |||
| 39 | 39 | EXPECT_EQ( | |
| 40 | 40 | PathResolve(*env, {"C:\\foo\\tmp.3\\", "..\\tmp.3\\cycles\\root.js"}), | |
| 41 | 41 | "C:\\foo\\tmp.3\\cycles\\root.js"); | |
| 42 | + EXPECT_EQ(PathResolve(*env, {"\\\\.\\PHYSICALDRIVE0"}), | ||
| 43 | + "\\\\.\\PHYSICALDRIVE0"); | ||
| 44 | + EXPECT_EQ(PathResolve(*env, {"\\\\?\\PHYSICALDRIVE0"}), | ||
| 45 | + "\\\\?\\PHYSICALDRIVE0"); | ||
| 42 | 46 | #else | |
| 43 | 47 | EXPECT_EQ(PathResolve(*env, {"/var/lib", "../", "file/"}), "/var/file"); | |
| 44 | 48 | EXPECT_EQ(PathResolve(*env, {"/var/lib", "/../", "file/"}), "/file"); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -79,7 +79,7 @@ assert.strictEqual(path.win32.toNamespacedPath('\\\\foo\\bar'), | |||
| 79 | 79 | '\\\\?\\UNC\\foo\\bar\\'); | |
| 80 | 80 | assert.strictEqual(path.win32.toNamespacedPath('//foo//bar'), | |
| 81 | 81 | '\\\\?\\UNC\\foo\\bar\\'); | |
| 82 | - assert.strictEqual(path.win32.toNamespacedPath('\\\\?\\foo'), '\\\\?\\foo\\'); | ||
| 82 | + assert.strictEqual(path.win32.toNamespacedPath('\\\\?\\foo'), '\\\\?\\foo'); | ||
| 83 | 83 | assert.strictEqual(path.win32.toNamespacedPath('\\\\?\\c:\\Windows/System'), '\\\\?\\c:\\Windows\\System'); | |
| 84 | 84 | assert.strictEqual(path.win32.toNamespacedPath(null), null); | |
| 85 | 85 | assert.strictEqual(path.win32.toNamespacedPath(true), true); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -40,6 +40,8 @@ assert.strictEqual( | |||
| 40 | 40 | '..\\..\\..\\..\\baz' | |
| 41 | 41 | ); | |
| 42 | 42 | assert.strictEqual(path.win32.normalize('foo/bar\\baz'), 'foo\\bar\\baz'); | |
| 43 | + assert.strictEqual(path.win32.normalize('\\\\.\\foo'), '\\\\.\\foo'); | ||
| 44 | + assert.strictEqual(path.win32.normalize('\\\\.\\foo\\'), '\\\\.\\foo\\'); | ||
| 43 | 45 | ||
| 44 | 46 | // Tests related to CVE-2024-36139. Path traversal should not result in changing | |
| 45 | 47 | // the root directory on Windows. | |
@@ -58,10 +60,10 @@ assert.strictEqual(path.win32.normalize('/test/../??/D:/Test'), '\\??\\D:\\Test' | |||
| 58 | 60 | assert.strictEqual(path.win32.normalize('/test/../?/D:/Test'), '\\?\\D:\\Test'); | |
| 59 | 61 | assert.strictEqual(path.win32.normalize('//test/../??/D:/Test'), '\\\\test\\..\\??\\D:\\Test'); | |
| 60 | 62 | assert.strictEqual(path.win32.normalize('//test/../?/D:/Test'), '\\\\test\\..\\?\\D:\\Test'); | |
| 61 | - assert.strictEqual(path.win32.normalize('\\\\?\\test/../?/D:/Test'), '\\\\?\\test\\?\\D:\\Test'); | ||
| 62 | - assert.strictEqual(path.win32.normalize('\\\\?\\test/../../?/D:/Test'), '\\\\?\\test\\?\\D:\\Test'); | ||
| 63 | - assert.strictEqual(path.win32.normalize('\\\\.\\test/../?/D:/Test'), '\\\\.\\test\\?\\D:\\Test'); | ||
| 64 | - assert.strictEqual(path.win32.normalize('\\\\.\\test/../../?/D:/Test'), '\\\\.\\test\\?\\D:\\Test'); | ||
| 63 | + assert.strictEqual(path.win32.normalize('\\\\?\\test/../?/D:/Test'), '\\\\?\\?\\D:\\Test'); | ||
| 64 | + assert.strictEqual(path.win32.normalize('\\\\?\\test/../../?/D:/Test'), '\\\\?\\?\\D:\\Test'); | ||
| 65 | + assert.strictEqual(path.win32.normalize('\\\\.\\test/../?/D:/Test'), '\\\\.\\?\\D:\\Test'); | ||
| 66 | + assert.strictEqual(path.win32.normalize('\\\\.\\test/../../?/D:/Test'), '\\\\.\\?\\D:\\Test'); | ||
| 65 | 67 | assert.strictEqual(path.win32.normalize('//server/share/dir/../../../?/D:/file'), | |
| 66 | 68 | '\\\\server\\share\\?\\D:\\file'); | |
| 67 | 69 | assert.strictEqual(path.win32.normalize('//server/goodshare/../badshare/file'), | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -35,6 +35,8 @@ const resolveTests = [ | |||
| 35 | 35 | [['c:/', '///some//dir'], 'c:\\some\\dir'], | |
| 36 | 36 | [['C:\\foo\\tmp.3\\', '..\\tmp.3\\cycles\\root.js'], | |
| 37 | 37 | 'C:\\foo\\tmp.3\\cycles\\root.js'], | |
| 38 | + [['\\\\.\\PHYSICALDRIVE0'], '\\\\.\\PHYSICALDRIVE0'], | ||
| 39 | + [['\\\\?\\PHYSICALDRIVE0'], '\\\\?\\PHYSICALDRIVE0'], | ||
| 38 | 40 | ], | |
| 39 | 41 | ], | |
| 40 | 42 | [ path.posix.resolve, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments