MCPcopy Create free account
hub / github.com/buger/jsonparser / injectPathHazard

Function injectPathHazard

json_fuzz_test.go:977–992  ·  view source on GitHub ↗

injectPathHazard randomly injects an adversarial path component into an existing path. This implements the injectEmptyKeyComponent and injectOobArrayIndex operators from the spec.

(r *rand.Rand, path []string)

Source from the content-addressed store, hash-verified

975// existing path. This implements the injectEmptyKeyComponent and
976// injectOobArrayIndex operators from the spec.
977func injectPathHazard(r *rand.Rand, path []string) []string {
978 switch r.Intn(3) {
979 case 0: // injectEmptyKeyComponent — append "" to the path
980 out := make([]string, len(path)+1)
981 copy(out, path)
982 out[len(path)] = ""
983 return out
984 case 1: // injectOobArrayIndex — append "[99]" to the path
985 out := make([]string, len(path)+1)
986 copy(out, path)
987 out[len(path)] = "[99]"
988 return out
989 default: // replace with a grammar-generated adversarial path
990 return genKeyPath(r)
991 }
992}
993
994// =============================================================================
995// Enhanced path-shape checker (catches nested D6 divergences)

Callers 1

FuzzJSONStructureAwareFunction · 0.85

Calls 1

genKeyPathFunction · 0.85

Tested by

no test coverage detected