summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--package.json3
-rwxr-xr-xrtt-module.js25
2 files changed, 26 insertions, 2 deletions
diff --git a/package.json b/package.json
index 31c2ca9..70a9d6b 100644
--- a/package.json
+++ b/package.json
@@ -7,6 +7,7 @@
"dryRun": "jazzer rtt-module --sync -- -runs=100 -seed=123456789"
},
"dependencies": {
- "@jazzer.js/core": "^1.6.1"
+ "@jazzer.js/core": "^1.6.1",
+ "ajv": "^8.12.0"
}
}
diff --git a/rtt-module.js b/rtt-module.js
index ceb795d..fa363ca 100755
--- a/rtt-module.js
+++ b/rtt-module.js
@@ -1,5 +1,7 @@
"use strict"
+const Ajv = require("ajv")
+const ajv = new Ajv()
const fs = require("fs")
const { FuzzedDataProvider } = require("@jazzer.js/core")
@@ -14,6 +16,12 @@ if (!fs.existsSync(RULES_JS_FILE)) {
}
const RULES = require(RULES_JS_FILE)
+let rules_view_schema = null
+if (RULES.VIEW_SCHEMA) {
+ console.log("View schema found; validating.")
+ rules_view_schema = ajv.compile(RULES.VIEW_SCHEMA)
+}
+
module.exports.fuzz = function(fuzzerInputData) {
let data = new FuzzedDataProvider(fuzzerInputData)
if (data.remainingBytes < 16) {
@@ -53,6 +61,14 @@ module.exports.fuzz = function(fuzzerInputData) {
log_crash(game_setup, state, view, step, active)
throw new RulesCrashError(e, e.stack)
}
+
+ if (rules_view_schema) {
+ if (!rules_view_schema(view)) {
+ log_crash(game_setup, state, view, step, active)
+ console.log(rules_view_schema.errors)
+ throw new SchemaValidationError("View data fails schema validation")
+ }
+ }
if (step > MAX_STEPS) {
log_crash(game_setup, state, view, step, active)
@@ -102,7 +118,7 @@ module.exports.fuzz = function(fuzzerInputData) {
}
args = data.pickValue(args)
}
- // console.log(action, args)
+ // console.log(active, action, args)
try {
if (action !== "_resign") {
state = RULES.action(state, active, action, args)
@@ -161,3 +177,10 @@ class RulesCrashError extends Error {
this.stack = stack
}
}
+
+class SchemaValidationError extends Error {
+ constructor(message) {
+ super(message)
+ this.name = "SchemaValidationError"
+ }
+}