mirror of
https://github.com/nodejs/node.git
synced 2026-11-27 17:52:27 -05:00
fs: coerce -0 to +0 in mode flags and watch intervals
Signed-off-by: Filip Skokan <panva.ip@gmail.com> PR-URL: https://github.com/nodejs/node/pull/63556 Reviewed-By: Jordan Harband <ljharb@gmail.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
This commit is contained in:
1 parent
d4cfe2d8ac
commit
d3d7cd05e3
4 files changed
+39
-2
No files matched your search
@@ -592,7 +592,8 @@ function getStatFsFromBinding(stats) {
|
||||
function stringToFlags(flags, name = 'flags') {
|
||||
if (typeof flags === 'number') {
|
||||
validateInt32(flags, name);
|
||||
return flags;
|
||||
// Coerce -0 to +0.
|
||||
return flags + 0;
|
||||
}
|
||||
|
||||
if (flags == null) {
|
||||
|
||||
@@ -176,6 +176,8 @@ StatWatcher.prototype[kFSStatWatcherStart] = function(filename,
|
||||
|
||||
filename = getValidatedPath(filename, 'filename');
|
||||
validateUint32(interval, 'interval');
|
||||
// Coerce -0 to +0.
|
||||
interval += 0;
|
||||
const err = this._handle.start(toNamespacedPath(filename), interval);
|
||||
if (err) {
|
||||
const error = new UVException({
|
||||
|
||||
@@ -80,7 +80,8 @@ function parseFileMode(value, name, def) {
|
||||
}
|
||||
|
||||
validateUint32(value, name);
|
||||
return value;
|
||||
// Coerce -0 to +0.
|
||||
return value + 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
'use strict';
|
||||
|
||||
require('../common');
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const os = require('os');
|
||||
|
||||
const missing = path.join(
|
||||
os.tmpdir(),
|
||||
`node-fs-negative-zero-${process.pid}`,
|
||||
'entry',
|
||||
);
|
||||
|
||||
function ignoreExpectedError(fn) {
|
||||
try {
|
||||
fn();
|
||||
} catch {
|
||||
// Ignore expected file system errors from the missing path.
|
||||
}
|
||||
}
|
||||
|
||||
const fd = fs.openSync(process.execPath, -0);
|
||||
fs.closeSync(fd);
|
||||
|
||||
ignoreExpectedError(() => fs.openSync(process.execPath, 'r', -0));
|
||||
ignoreExpectedError(() => fs.readFileSync(process.execPath, { flag: -0 }));
|
||||
ignoreExpectedError(() => fs.mkdirSync(missing, { mode: -0 }));
|
||||
ignoreExpectedError(() => fs.chmodSync(missing, -0));
|
||||
ignoreExpectedError(() => fs.writeFileSync(missing, '', { mode: -0 }));
|
||||
|
||||
fs.watchFile(missing, { interval: -0 }, () => {});
|
||||
fs.unwatchFile(missing);
|
||||
Reference in new issue
Block a user