Skip to content

Commit

Permalink
Fix access check
Browse files Browse the repository at this point in the history
Signed-off-by: Marcos Candeia <[email protected]>
  • Loading branch information
mcandeia committed Nov 11, 2024
1 parent cb55a18 commit 9a9f538
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,24 @@ export abstract class StatsCommon<T extends number | bigint> implements Node.Sta
* @internal
*/
public hasAccess(mode: number): boolean {
// Assuming 'credentials' and 'this.uid', 'this.gid', 'this.mode' are accessible
if (credentials.euid === 0 || credentials.egid === 0) {
//Running as root
// Running as root
return true;
}

// Mask for
const adjusted = (credentials.uid == this.uid ? S_IRWXU : 0) | (credentials.gid == this.gid ? S_IRWXG : 0) | S_IRWXO;
return (mode & this.mode & adjusted) == mode;
// Build the adjusted permission mask based on ownership
let adjusted = 0;
if (credentials.uid === this.uid) {
adjusted |= S_IRWXU; // Include owner permissions
}
if (credentials.gid === this.gid) {
adjusted |= S_IRWXG; // Include group permissions
}
adjusted |= S_IRWXO; // Always include others' permissions

// Perform the access check
return (this.mode & adjusted & mode) === mode;
}

/**
Expand Down

0 comments on commit 9a9f538

Please sign in to comment.