Skip to content

check if `fuzz` function is exported

FUJI Goro requested to merge gfx1/jsfuzz:validate_fuzz_function_exported into master

When a fuzz module has no fuzz function exported, the error message seems hard to recognize:

#0 READ units: 0
=================================================================
TypeError: Cannot read property 'constructor' of undefined
    at process.<anonymous> (/path/to/home/.nodebrew/node/v16.0.0/lib/node_modules/@gitlab-org/jsfuzz/build/src/worker.js:49:33)
    at process.emit (node:events:365:28)
    at emit (node:internal/child_process:920:12)
    at processTicksAndRejections (node:internal/process/task_queues:84:21)
crash was written to crash-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
crash(hex)=
Worker exited

With this patch, it will become much better:

#0 READ units: 0
/path/to/home/.nodebrew/node/v16.0.0/lib/node_modules/@gitlab-org/jsfuzz/build/src/worker.js:87
    throw new Error(`${fuzzTargetPath} has no fuzz function exported`);
    ^

Error: /path/to/project/test/jsfuzz.js has no fuzz function exported
    at Object.<anonymous> (/path/to/home/.nodebrew/node/v16.0.0/lib/node_modules/@gitlab-org/jsfuzz/build/src/worker.js:87:11)
    at Module._compile (node:internal/modules/cjs/loader:1108:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
    at Module.load (node:internal/modules/cjs/loader:988:32)
    at Function.Module._load (node:internal/modules/cjs/loader:828:14)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
    at node:internal/main/run_main_module:17:47
Worker exited

I had this kind of mistake by writing something wrong like this:

module.exports = function fuzz () { ... };

Of course, the following one is correct:

module.exports.fuzz = function fuzz () { ... };

Merge request reports