| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 6f580d5 commit 183353a
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -285,10 +285,16 @@ const win32 = { | |||
| 285 | 285 | j++; | |
| 286 | 286 | } | |
| 287 | 287 | if (j === len || j !== last) { | |
| 288 | - // We matched a UNC root | ||
| 289 | - device = | ||
| 290 | - `\\\\${firstPart}\\${StringPrototypeSlice(path, last, j)}`; | ||
| 291 | - rootEnd = j; | ||
| 288 | + if (firstPart !== '.' && firstPart !== '?') { | ||
| 289 | + // We matched a UNC root | ||
| 290 | + device = | ||
| 291 | + `\\\\${firstPart}\\${StringPrototypeSlice(path, last, j)}`; | ||
| 292 | + rootEnd = j; | ||
| 293 | + } else { | ||
| 294 | + // We matched a device root (e.g. \\\\.\\PHYSICALDRIVE0) | ||
| 295 | + device = `\\\\${firstPart}`; | ||
| 296 | + rootEnd = 4; | ||
| 297 | + } | ||
| 292 | 298 | } | |
| 293 | 299 | } | |
| 294 | 300 | } | |
@@ -398,17 +404,22 @@ const win32 = { | |||
| 398 | 404 | !isPathSeparator(StringPrototypeCharCodeAt(path, j))) { | |
| 399 | 405 | j++; | |
| 400 | 406 | } | |
| 401 | - if (j === len) { | ||
| 402 | - // We matched a UNC root only | ||
| 403 | - // Return the normalized version of the UNC root since there | ||
| 404 | - // is nothing left to process | ||
| 405 | - return `\\\\${firstPart}\\${StringPrototypeSlice(path, last)}\\`; | ||
| 406 | - } | ||
| 407 | - if (j !== last) { | ||
| 408 | - // We matched a UNC root with leftovers | ||
| 409 | - device = | ||
| 410 | - `\\\\${firstPart}\\${StringPrototypeSlice(path, last, j)}`; | ||
| 411 | - rootEnd = j; | ||
| 407 | + if (j === len || j !== last) { | ||
| 408 | + if (firstPart === '.' || firstPart === '?') { | ||
| 409 | + // We matched a device root (e.g. \\\\.\\PHYSICALDRIVE0) | ||
| 410 | + device = `\\\\${firstPart}`; | ||
| 411 | + rootEnd = 4; | ||
| 412 | + } else if (j === len) { | ||
| 413 | + // We matched a UNC root only | ||
| 414 | + // Return the normalized version of the UNC root since there | ||
| 415 | + // is nothing left to process | ||
| 416 | + return `\\\\${firstPart}\\${StringPrototypeSlice(path, last)}\\`; | ||
| 417 | + } else { | ||
| 418 | + // We matched a UNC root with leftovers | ||
| 419 | + device = | ||
| 420 | + `\\\\${firstPart}\\${StringPrototypeSlice(path, last, j)}`; | ||
| 421 | + rootEnd = j; | ||
| 422 | + } | ||
| 412 | 423 | } | |
| 413 | 424 | } | |
| 414 | 425 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -171,9 +171,16 @@ std::string PathResolve(Environment* env, | |||
| 171 | 171 | j++; | |
| 172 | 172 | } | |
| 173 | 173 | if (j == len || j != last) { | |
| 174 | - // We matched a UNC root | ||
| 175 | - device = "\\\\" + firstPart + "\\" + path.substr(last, j - last); | ||
| 176 | - rootEnd = j; | ||
| 174 | + if (firstPart != "." && firstPart != "?") { | ||
| 175 | + // We matched a UNC root | ||
| 176 | + device = | ||
| 177 | + "\\\\" + firstPart + "\\" + path.substr(last, j - last); | ||
| 178 | + rootEnd = j; | ||
| 179 | + } else { | ||
| 180 | + // We matched a device root (e.g. \\\\.\\PHYSICALDRIVE0) | ||
| 181 | + device = "\\\\" + firstPart; | ||
| 182 | + rootEnd = 4; | ||
| 183 | + } | ||
| 177 | 184 | } | |
| 178 | 185 | } | |
| 179 | 186 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -35,6 +35,10 @@ TEST_F(PathTest, PathResolve) { | |||
| 35 | 35 | EXPECT_EQ( | |
| 36 | 36 | PathResolve(*env, {"C:\\foo\\tmp.3\\", "..\\tmp.3\\cycles\\root.js"}), | |
| 37 | 37 | "C:\\foo\\tmp.3\\cycles\\root.js"); | |
| 38 | + EXPECT_EQ(PathResolve(*env, {"\\\\.\\PHYSICALDRIVE0"}), | ||
| 39 | + "\\\\.\\PHYSICALDRIVE0"); | ||
| 40 | + EXPECT_EQ(PathResolve(*env, {"\\\\?\\PHYSICALDRIVE0"}), | ||
| 41 | + "\\\\?\\PHYSICALDRIVE0"); | ||
| 38 | 42 | #else | |
| 39 | 43 | EXPECT_EQ(PathResolve(*env, {"/var/lib", "../", "file/"}), "/var/file"); | |
| 40 | 44 | 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 | |
|---|---|---|---|
@@ -33,6 +33,8 @@ const resolveTests = [ | |||
| 33 | 33 | [['c:/', '///some//dir'], 'c:\\some\\dir'], | |
| 34 | 34 | [['C:\\foo\\tmp.3\\', '..\\tmp.3\\cycles\\root.js'], | |
| 35 | 35 | 'C:\\foo\\tmp.3\\cycles\\root.js'], | |
| 36 | + [['\\\\.\\PHYSICALDRIVE0'], '\\\\.\\PHYSICALDRIVE0'], | ||
| 37 | + [['\\\\?\\PHYSICALDRIVE0'], '\\\\?\\PHYSICALDRIVE0'], | ||
| 36 | 38 | ], | |
| 37 | 39 | ], | |
| 38 | 40 | [ path.posix.resolve, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments