aboutsummaryrefslogtreecommitdiff
path: root/test/bun.js
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-01-18 01:16:13 -0800
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-01-18 01:16:13 -0800
commit2db04ef9d9ddf6531b0a77c3b0867bc80388a039 (patch)
tree6430e9e6f8043897ddab77f07515ddb4212d94c7 /test/bun.js
parent4cb6a34432899df08ac4174334ab7d6a374a48e2 (diff)
downloadbun-v0.5.0.tar.gz
bun-v0.5.0.tar.zst
bun-v0.5.0.zip
Fix crash with invalid arguments in readdir()bun-v0.5.0
Diffstat (limited to 'test/bun.js')
-rw-r--r--test/bun.js/fs.test.js30
1 files changed, 29 insertions, 1 deletions
diff --git a/test/bun.js/fs.test.js b/test/bun.js/fs.test.js
index ac2357143..058a40828 100644
--- a/test/bun.js/fs.test.js
+++ b/test/bun.js/fs.test.js
@@ -548,7 +548,9 @@ describe("fs/promises", () => {
const { readFile, stat, writeFile } = promises;
it("should not segfault on exception", async () => {
- stat("foo/bar");
+ try {
+ await stat("foo/bar");
+ } catch (e) {}
});
it("readFile", async () => {
@@ -561,4 +563,30 @@ describe("fs/promises", () => {
await writeFile(path, "File written successfully");
expect(readFileSync(path, "utf8")).toBe("File written successfully");
});
+
+ it("readdir()", async () => {
+ const files = await promises.readdir(import.meta.dir);
+ expect(files.length).toBeGreaterThan(0);
+ });
+
+ it("readdir() no args doesnt segfault", async () => {
+ const fizz = [
+ [],
+ [Symbol("ok")],
+ [Symbol("ok"), Symbol("ok")],
+ [Symbol("ok"), Symbol("ok"), Symbol("ok")],
+ [Infinity, -NaN, -Infinity],
+ "\0\0\0\0",
+ "\r\n",
+ ];
+ for (const args of fizz) {
+ try {
+ // check it doens't segfault when called with invalid arguments
+ await promises.readdir(...args);
+ } catch (e) {
+ // check that producing the error doesn't cause any crashes
+ Bun.inspect(e);
+ }
+ }
+ });
});