-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src: fix validation of negative offset to avoid abort
Fixes: #24640 Signed-off-by: James M Snell <jasnell@gmail.com> PR-URL: #38421 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Nitzan Uziely <linkgoron@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com>
- Loading branch information
Showing
5 changed files
with
65 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
'use strict'; | ||
|
||
// Tests that passing a negative offset does not crash the process | ||
|
||
const common = require('../common'); | ||
|
||
const { | ||
join, | ||
} = require('path'); | ||
|
||
const { | ||
closeSync, | ||
open, | ||
write, | ||
writeSync, | ||
} = require('fs'); | ||
|
||
const assert = require('assert'); | ||
|
||
const tmpdir = require('../common/tmpdir'); | ||
tmpdir.refresh(); | ||
|
||
const filename = join(tmpdir.path, 'test.txt'); | ||
|
||
open(filename, 'w+', common.mustSucceed((fd) => { | ||
assert.throws(() => { | ||
write(fd, Buffer.alloc(0), -1, common.mustNotCall()); | ||
}, { | ||
code: 'ERR_OUT_OF_RANGE', | ||
}); | ||
assert.throws(() => { | ||
writeSync(fd, Buffer.alloc(0), -1); | ||
}, { | ||
code: 'ERR_OUT_OF_RANGE', | ||
}); | ||
closeSync(fd); | ||
})); | ||
|
||
const filename2 = join(tmpdir.path, 'test2.txt'); | ||
|
||
// Make sure negative length's don't cause aborts either | ||
|
||
open(filename2, 'w+', common.mustSucceed((fd) => { | ||
assert.throws(() => { | ||
write(fd, Buffer.alloc(0), 0, -1, common.mustNotCall()); | ||
}, { | ||
code: 'ERR_OUT_OF_RANGE', | ||
}); | ||
assert.throws(() => { | ||
writeSync(fd, Buffer.alloc(0), 0, -1); | ||
}, { | ||
code: 'ERR_OUT_OF_RANGE', | ||
}); | ||
closeSync(fd); | ||
})); |