summaryrefslogtreecommitdiff
path: root/rtt-module.js
diff options
context:
space:
mode:
Diffstat (limited to 'rtt-module.js')
-rwxr-xr-xrtt-module.js25
1 files changed, 24 insertions, 1 deletions
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"
+ }
+}