Skip to content

Commit 0864835

Browse files
BartSchuurmanscristianoc
authored andcommitted
rescript format -stdin: only create temp file if the name doesn't exist, and use mode 0o600
We should not accidentally overwrite a random file.
1 parent db51309 commit 0864835

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/rescript_format.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,9 @@ function main(argv, rescript_exe, bsc_exe) {
126126
);
127127
(async function () {
128128
var content = await readStdin();
129-
fs.writeFileSync(filename, content, "utf8");
129+
var fd = fs.openSync(filename, "wx", 0o600);
130+
fs.writeFileSync(fd, content, "utf8");
131+
fs.closeSync(fd);
130132
process.addListener("exit", () => fs.unlinkSync(filename));
131133
child_process.execFile(
132134
bsc_exe,

0 commit comments

Comments
 (0)