Skip to content

Commit 89dde27

Browse files
committed
chore: revert "toctou" handling
1 parent 66c8d4e commit 89dde27

File tree

2 files changed

+9
-27
lines changed

2 files changed

+9
-27
lines changed

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,3 @@ node_modules
66
*.mov
77
*.vsix
88
*.sarif*
9-
PLAN.md
10-
codeql-alerts.json

src/codeMarker.ts

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -912,30 +912,18 @@ class WARoot {
912912
async updateSavedData(username: string): Promise<void> {
913913
const vscodeFolder = path.join(this.rootPath, ".vscode");
914914

915+
let existsFolder = true;
915916
let existsFile = true;
916917
let toCreateData = false;
917918

918-
// Atomically ensure .vscode directory exists (no TOCTOU vulnerability)
919-
// This will succeed even if the directory already exists
920-
try {
921-
fs.mkdirSync(vscodeFolder, { recursive: true });
922-
} catch (error: any) {
923-
// Only throw if it's not an EEXIST error (which shouldn't happen with recursive: true anyway)
924-
if (error.code !== "EEXIST") {
925-
throw error;
926-
}
919+
if (!fs.existsSync(vscodeFolder)) {
920+
existsFolder = false;
927921
}
928922

929923
const fileName = path.join(vscodeFolder, username + SERIALIZED_FILE_EXTENSION);
930924
const wsRootEntry = { label: this.rootLabel } as WorkspaceRootEntry;
931925
const configEntry = { path: fileName, username: username, root: wsRootEntry };
932-
933-
// Check if file exists by attempting to access it
934-
// This is still subject to TOCTOU but we handle it properly below
935-
try {
936-
fs.accessSync(fileName, fs.constants.F_OK);
937-
existsFile = true;
938-
} catch {
926+
if (!fs.existsSync(fileName)) {
939927
existsFile = false;
940928
}
941929

@@ -1020,7 +1008,10 @@ class WARoot {
10201008
}
10211009

10221010
if (toCreateData) {
1023-
// .vscode folder already created atomically at the start of this method
1011+
// create .vscode folder if it doesn't exist
1012+
if (!existsFolder) {
1013+
fs.mkdirSync(vscodeFolder);
1014+
}
10241015

10251016
// create a new config file if it doesn't exist
10261017
if (!existsFile) {
@@ -1047,14 +1038,7 @@ class WARoot {
10471038
2,
10481039
);
10491040

1050-
// Write file atomically with proper error handling
1051-
// Using 'w+' flag: creates file if it doesn't exist, truncates if it does
1052-
try {
1053-
fs.writeFileSync(fileName, data, { flag: "w+" });
1054-
} catch (error: any) {
1055-
console.error(`Failed to write audit data to ${fileName}:`, error);
1056-
throw new Error(`Failed to save audit data: ${error.message}`);
1057-
}
1041+
fs.writeFileSync(fileName, data, { flag: "w+" });
10581042
}
10591043
}
10601044

0 commit comments

Comments
 (0)