Skip to content

Commit bdf5495

Browse files
committed
Prevent FSHelper.rmdir from following symlinks when checking for a mountpoint
1 parent 906359d commit bdf5495

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

packages/php-wasm/node/src/test/mount.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,7 @@ describe('Mounting', () => {
459459
try {
460460
await php.rmdir(directoryMountPoint);
461461
} catch (e: any) {
462+
console.log(e);
462463
const error = e as Error;
463464
expect(error.message).toContain(
464465
`Could not remove directory "${directoryMountPoint}": Device or resource busy.`

packages/php-wasm/universal/src/lib/fs-helpers.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,13 @@ export class FSHelpers {
139139
* To prevent the recursive option from removing internal files before
140140
* failing to remove the mount point, we need to check if the path is a
141141
* mount point and throw an error early.
142+
*
143+
* Because a mountpoint can be a symlink, we should not follow it.
144+
* Otherwise, a mounted sylink would point to the symlinked path,
145+
* instead of the mountpoint.
142146
*/
143-
const mountPoint = FS.lookupPath(path).node.mount;
144-
if (mountPoint.mountpoint === path) {
147+
const mountPoint = FS.lookupPath(path, { follow: false });
148+
if (mountPoint?.node.mount.mountpoint === path) {
145149
throw new ErrnoError(10);
146150
}
147151

0 commit comments

Comments
 (0)