summaryrefslogtreecommitdiff
path: root/rtt-module.js
diff options
context:
space:
mode:
authorMischa Untaga <99098079+MischaU8@users.noreply.github.com>2024-01-04 10:25:48 +0100
committerMischa Untaga <99098079+MischaU8@users.noreply.github.com>2024-01-04 10:25:48 +0100
commit0dbb2b025a1a71fe3f2559ff442b60455db828b5 (patch)
tree8a37e03b315f50fc803f12bfbb5be5a33846960c /rtt-module.js
parent033555b3e70903c048f94d5ed038cc299435a1f3 (diff)
downloadfuzzer-0dbb2b025a1a71fe3f2559ff442b60455db828b5.tar.gz
re-add MAX_STEPS
Diffstat (limited to 'rtt-module.js')
-rwxr-xr-xrtt-module.js20
1 files changed, 20 insertions, 0 deletions
diff --git a/rtt-module.js b/rtt-module.js
index b1df281..b7e727d 100755
--- a/rtt-module.js
+++ b/rtt-module.js
@@ -8,6 +8,7 @@ const { FuzzedDataProvider } = require("@jazzer.js/core")
const RULES_JS_FILE = process.env.RTT_RULES || "rules.js"
const NO_UNDO = process.env.NO_UNDO === 'true'
const NO_SCHEMA = process.env.NO_SCHEMA === 'true'
+const MAX_STEPS = parseInt(process.env.MAX_STEPS || 0)
console.log(`Loading rtt-fuzzer RTT_RULES='${RULES_JS_FILE}'`)
if (!fs.existsSync(RULES_JS_FILE)) {
@@ -48,6 +49,12 @@ module.exports.fuzz = function(fuzzerInputData) {
// insufficient bytes to continue
return
}
+
+ if (MAX_STEPS < 0 && step > -MAX_STEPS) {
+ // Skip & ignore if we reach the limit
+ return
+ }
+
let active = state.active
if (active === 'Both' || active === 'All') {
// If multiple players can act, we'll pick a random player to go first.
@@ -62,6 +69,11 @@ module.exports.fuzz = function(fuzzerInputData) {
throw new RulesCrashError(e, e.stack)
}
+ if (MAX_STEPS > 0 && step > MAX_STEPS) {
+ log_crash(game_setup, state, view, step, active)
+ throw new MaxStepError("MAX_STEPS reached")
+ }
+
if (rules_view_schema && !rules_view_schema(view)) {
log_crash(game_setup, state, view, step, active)
console.log(rules_view_schema.errors)
@@ -100,6 +112,7 @@ module.exports.fuzz = function(fuzzerInputData) {
log_crash(game_setup, state, view, step, active)
throw new NoMoreActionsError("No more actions to take (besides undo)")
}
+
let action = data.pickValue(Object.keys(actions))
let args = actions[action]
@@ -147,6 +160,13 @@ class UnknownStateError extends Error {
}
}
+class MaxStepError extends Error {
+ constructor(message) {
+ super(message)
+ this.name = "MaxStepError"
+ }
+}
+
class NoMoreActionsError extends Error {
constructor(message) {
super(message)