Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/fuzzer/fuzzer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ describe("compare hooks", () => {
expect(fuzzer.tracer.traceStrCmp("a", "b", "!=", 0)).toBe(true);
expect(fuzzer.tracer.traceStrCmp("a", "b", "!==", 0)).toBe(true);
});

it("traceStrCmp handles objects of unknown types", () => {
const foo = () => 5;
expect(fuzzer.tracer.traceStrCmp(foo, "foo", "==", 0)).toBe(false);
expect(fuzzer.tracer.traceStrCmp(foo, "foo", "===", 0)).toBe(false);
expect(fuzzer.tracer.traceStrCmp(foo, "foo", "!=", 0)).toBe(true);
expect(fuzzer.tracer.traceStrCmp(foo, "foo", "!==", 0)).toBe(true);
});
});

describe("incrementCounter", () => {
Expand Down
16 changes: 11 additions & 5 deletions packages/fuzzer/trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ import { addon } from "./addon";
* Performs a string comparison between two strings and calls the corresponding native hook if needed.
* This function replaces the original comparison expression and preserves the semantics by returning
* the original result after calling the native hook.
* @param s1 first compared string
* @param s2 second compared string
* @param s1 first compared string. s1 has the type `unknown` because we can only know the type at runtime.
* @param s2 second compared string. s2 has the type `unknown` because we can only know the type at runtime.
* @param operator the operator used in the comparison
* @param id an unique identifier to distinguish between the different comparisons
* @returns result of the comparison
*/
function traceStrCmp(
s1: string,
s2: string,
s1: unknown,
s2: unknown,
operator: string,
id: number
): boolean {
Expand All @@ -52,7 +52,13 @@ function traceStrCmp(
shouldCallLibfuzzer = result;
break;
}
if (shouldCallLibfuzzer && s1 && s2) {
if (
shouldCallLibfuzzer &&
s1 &&
s2 &&
typeof s1 === "string" &&
typeof s2 === "string"
) {
addon.traceUnequalStrings(id, s1, s2);
}
return result;
Expand Down