Skip to content

Commit bf3295e

Browse files
authored
js-yaml: fix driver (#13412)
There were three issues with the fuzz driver for js-yaml: 1. With `catch (YAMLException)` I believe the intent was to ignore instances of `YAMLException` only. However, catch statements like these would ignore _all_ exceptions in JavaScript. Added an explicit `instanceof` check. 2. `getSchema` does not have the intended `options` object in scope. Instead, it sets `schema` on the _global_ options object that Jazzer.js [defines](https://github.com/CodeIntelligenceTesting/jazzer.js/blob/592be5c6d7f453e96822be41fe3f2a1351b8fd96/packages/core/core.ts#L129). Return a schema from `getSchema` instead. 3. Schemas are supposed to be instances of the `Schema` class, not strings. Replace string values with the constants this library [exports](https://github.com/nodeca/js-yaml/blob/0d3ca7a27b03a6c974790a30a89e456007d62976/index.js#L21).
1 parent fac9e51 commit bf3295e

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

projects/js-yaml/fuzz.js

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ module.exports.fuzz = function(data) {
2727
try {
2828
const parsedYaml = yaml.load(yamlString, loadOptions);
2929
const _serializedYaml = yaml.dump(parsedYaml, dumpOptions);
30-
} catch (YAMLException) {
30+
} catch (e) {
31+
if (!(e instanceof yaml.YAMLException)) {
32+
throw e
33+
}
3134
}
3235
};
3336

@@ -56,19 +59,10 @@ function generateRandomDumpOptions(provider) {
5659

5760

5861
function getSchema(number) {
59-
6062
switch (number) {
61-
case 0:
62-
options.schema = "DEFAULT_SCHEMA";
63-
break
64-
case 1:
65-
options.schema = "FAILSAFE_SCHEMA";
66-
break
67-
case 2:
68-
options.schema = "JSON_SCHEMA";
69-
break
70-
case 3:
71-
options.schema = "CORE_SCHEMA";
72-
break
63+
case 0: return yaml.DEFAULT_SCHEMA
64+
case 1: return yaml.FAILSAFE_SCHEMA
65+
case 2: return yaml.JSON_SCHEMA
66+
case 3: return yaml.CORE_SCHEMA
7367
}
7468
}

0 commit comments

Comments
 (0)