159159
160160
161161
162+ --- Recursively fuzzes a single command
163+ -- To be used only inside fuzzCommand!
164+ -- a_CurrentIndex is the index into the a_Split array specifying the index that this recursion level should modify
165+ -- a_Split is the command params split array
166+ -- The recursion is called "backwards", the last param is chosen first and then the previous param is recursed
167+ -- When a_CurrentIndex is zero, the actual command handlers are invoked
168+ local function fuzzSingleCommand (a_Simulator , a_Command , a_PlayerName , a_Choices , a_NumChoices , a_CurrentIndex , a_Split )
169+ if (a_CurrentIndex == 0 ) then
170+ -- We've built the whole command, serialize the params into a string and execute it:
171+ a_Simulator .logger :info (" Scenario: fuzzing command \" %s\" ." , a_Command .. " " .. table.concat (a_Split , " " ))
172+ a_Simulator :executePlayerCommand (a_PlayerName , a_Command .. " " .. table.concat (a_Split , " " ))
173+ -- Process all queued callbacks:
174+ a_Simulator :processAllQueuedCallbackRequests ()
175+ return
176+ end
177+
178+ -- Try all choices on position <a_CurrentIndex> and recurse:
179+ for ch = 1 , a_NumChoices do
180+ a_Split [a_CurrentIndex ] = a_Choices [ch ]
181+ fuzzSingleCommand (a_Simulator , a_Command , a_PlayerName , a_Choices , a_NumChoices , a_CurrentIndex - 1 , a_Split )
182+ end
183+ end
184+
185+
186+
187+
188+
162189--- Fuzzes a single command
163190-- a_Simulator is the simulator instance on which to fuzz the commands
164191-- a_Command is the registered command (string) being fuzzed
167194-- a_MinLen is the minimum length of the fuzzed command parameter array
168195-- a_MaxLen is the maximum length of the fuzzed command parameter array
169196local function fuzzCommand (a_Simulator , a_Command , a_PlayerName , a_Choices , a_MinLen , a_MaxLen )
170- -- Recursively fuzzes a single command
171- -- a_CurrentIndex is the index into the a_Split array specifying the index that this recursion level should modify
172- -- a_Split is the command params split array
173- -- The recursion is called "backwards", the last param is chosen first and then the previous param is recursed
174- -- When a_CurrentIndex is zero, the actual command handlers are invoked
175- local function fuzzSingleCommand (a_Simulator , a_Command , a_PlayerName , a_Choices , a_NumChoices , a_CurrentIndex , a_Split )
176- if (a_CurrentIndex == 0 ) then
177- -- We've built the whole command, serialize the params into a string and execute it:
178- a_Simulator .logger :info (" Scenario: fuzzing command \" %s\" ." , a_Command .. " " .. table.concat (a_Split , " " ))
179- a_Simulator :executePlayerCommand (a_PlayerName , a_Command .. " " .. table.concat (a_Split , " " ))
180- -- Process all queued callbacks:
181- a_Simulator :processAllQueuedCallbackRequests ()
182- return
183- end
184-
185- -- Try all choices on position <a_CurrentIndex> and recurse:
186- for ch = 1 , a_NumChoices do
187- a_Split [a_CurrentIndex ] = a_Choices [ch ]
188- fuzzSingleCommand (a_Simulator , a_Command , a_PlayerName , a_Choices , a_NumChoices , a_CurrentIndex - 1 , a_Split )
189- end
190- end
191-
192197 -- Start the fuzzing:
193198 for len = a_MinLen , a_MaxLen do
194199 fuzzSingleCommand (a_Simulator , a_Command , a_PlayerName , a_Choices , # a_Choices , len , {})
@@ -199,38 +204,43 @@ end
199204
200205
201206
207+ --- Recursively fuzzes a single console command
208+ -- To be used only inside FuzzConsoleCommand!
209+ -- a_CurrentIndex is the index into the a_Split array specifying the index that this recursion level should modify
210+ -- a_Split is the command params split array
211+ -- The recursion is called "backwards", the last param is chosen first and then the previous param is recursed
212+ -- When a_CurrentIndex is zero, the actual command handlers are invoked
213+ local function fuzzSingleConsoleCommand (a_Simulator , a_Command , a_Choices , a_NumChoices , a_CurrentIndex , a_Split )
214+ if (a_CurrentIndex == 0 ) then
215+ -- We've built the whole command, serialize the params into a string and execute it:
216+ a_Simulator .logger :info (" Scenario: fuzzing console command \" %s\" ." , a_Command .. " " .. table.concat (a_Split , " " ))
217+ a_Simulator :executeConsoleCommand (a_Command .. " " .. table.concat (a_Split , " " ))
218+ -- Process all queued callbacks:
219+ a_Simulator :processAllQueuedCallbackRequests ()
220+ return
221+ end
222+
223+ -- Try all choices on position <a_CurrentIndex> and recurse:
224+ for ch = 1 , a_NumChoices do
225+ a_Split [a_CurrentIndex ] = a_Choices [ch ]
226+ fuzzSingleConsoleCommand (a_Simulator , a_Command , a_Choices , a_NumChoices , a_CurrentIndex - 1 , a_Split )
227+ end
228+ end
229+
230+
231+
232+
233+
202234--- Fuzzes a single console command
203235-- a_Simulator is the simulator instance on which to fuzz the commands
204236-- a_Command is the registered command (string) being fuzzed
205237-- a_Choices is the array-table of choices for the command parameters
206238-- a_MinLen is the minimum length of the fuzzed command parameter array
207239-- a_MaxLen is the maximum length of the fuzzed command parameter array
208240local function fuzzConsoleCommand (a_Simulator , a_Command , a_Choices , a_MinLen , a_MaxLen )
209- -- Recursively fuzzes a single console command
210- -- a_CurrentIndex is the index into the a_Split array specifying the index that this recursion level should modify
211- -- a_Split is the command params split array
212- -- The recursion is called "backwards", the last param is chosen first and then the previous param is recursed
213- -- When a_CurrentIndex is zero, the actual command handlers are invoked
214- local function fuzzSingleCommand (a_Simulator , a_Command , a_Choices , a_NumChoices , a_CurrentIndex , a_Split )
215- if (a_CurrentIndex == 0 ) then
216- -- We've built the whole command, serialize the params into a string and execute it:
217- a_Simulator .logger :info (" Scenario: fuzzing console command \" %s\" ." , a_Command .. " " .. table.concat (a_Split , " " ))
218- a_Simulator :executeConsoleCommand (a_Command .. " " .. table.concat (a_Split , " " ))
219- -- Process all queued callbacks:
220- a_Simulator :processAllQueuedCallbackRequests ()
221- return
222- end
223-
224- -- Try all choices on position <a_CurrentIndex> and recurse:
225- for ch = 1 , a_NumChoices do
226- a_Split [a_CurrentIndex ] = a_Choices [ch ]
227- fuzzSingleCommand (a_Simulator , a_Command , a_Choices , a_NumChoices , a_CurrentIndex - 1 , a_Split )
228- end
229- end
230-
231241 -- Start the fuzzing:
232242 for len = a_MinLen , a_MaxLen do
233- fuzzSingleCommand (a_Simulator , a_Command , a_Choices , # a_Choices , len , {})
243+ fuzzSingleConsoleCommand (a_Simulator , a_Command , a_Choices , # a_Choices , len , {})
234244 end -- for len - number of chosen params
235245end
236246
0 commit comments