forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtest-fs-writesync-crash.js
More file actions
43 lines (35 loc) · 1000 Bytes
/
test-fs-writesync-crash.js
File metadata and controls
43 lines (35 loc) · 1000 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
'use strict';
require('../common');
const {
writeSync,
writeFileSync,
chmodSync,
openSync,
} = require('node:fs');
const {
throws,
} = require('node:assert');
// If a file's mode change after it is opened but before it is written to,
// and the Object.prototype is manipulated to throw an error when the errno
// or fd property is set or accessed, then the writeSync call would crash
// the process. This test verifies that the error is properly propagated
// instead.
const tmpdir = require('../common/tmpdir');
console.log(tmpdir.path);
tmpdir.refresh();
const path = `${tmpdir.path}/foo`;
writeFileSync(path, '');
// Do this after calling tmpdir.refresh() or that call will fail
// before we get to the part we want to test.
Object.defineProperty(Object.prototype, 'errno', {
__proto__: null,
set() {
throw new Error('error');
},
get() { return 0; }
});
const fd = openSync(path);
chmodSync(path, 0o600);
throws(() => writeSync(fd, 'test'), {
message: 'error',
});