node/test/parallel/test-fs-writesync-crash.js
James M Snell 538c813fa3
Some checks failed
Coverage Linux (without intl) / coverage-linux-without-intl (push) Waiting to run
Coverage Linux / coverage-linux (push) Waiting to run
Coverage Windows / coverage-windows (push) Waiting to run
Test and upload documentation to artifacts / build-docs (push) Waiting to run
Linters / lint-addon-docs (push) Waiting to run
Linters / lint-cpp (push) Waiting to run
Linters / format-cpp (push) Waiting to run
Linters / lint-js-and-md (push) Waiting to run
Linters / lint-py (push) Waiting to run
Linters / lint-yaml (push) Waiting to run
Linters / lint-sh (push) Waiting to run
Linters / lint-codeowners (push) Waiting to run
Linters / lint-pr-url (push) Waiting to run
Linters / lint-readme (push) Waiting to run
Notify on Push / Notify on Force Push on `main` (push) Waiting to run
Notify on Push / Notify on Push on `main` that lacks metadata (push) Waiting to run
Scorecard supply-chain security / Scorecard analysis (push) Waiting to run
Test internet / test-internet (push) Has been cancelled
src: fixup fs SyncCall to propagate errors correctly
Propagate errors correctly in the SyncCall utility.

Previously the test case would trigger a crash.

PR-URL: https://github.com/nodejs/node/pull/57711
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
2025-04-03 13:42:20 -07:00

43 lines
996 B
JavaScript

'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.
const error = new Error();
Object.defineProperty(Object.prototype, 'errno', {
__proto__: null,
set() {
throw error;
},
get() { return 0; }
});
const fd = openSync(path);
chmodSync(path, 0o600);
throws(() => writeSync(fd, 'test'), error);