genPathComponent returns a single adversarial path component.
(r *rand.Rand)
| 943 | |
| 944 | // genPathComponent returns a single adversarial path component. |
| 945 | func genPathComponent(r *rand.Rand) string { |
| 946 | switch r.Intn(12) { |
| 947 | case 0: // empty string (SYS-REQ-111 hazard — the 8th-panic class) |
| 948 | return "" |
| 949 | case 1: // valid array index in range |
| 950 | return "[" + strconv.Itoa(r.Intn(5)) + "]" |
| 951 | case 2: // out-of-range array index (SYS-REQ-110 hazard) |
| 952 | return "[99]" |
| 953 | case 3: // very large array index |
| 954 | return "[999999]" |
| 955 | case 4: // malformed array index syntax (empty brackets) |
| 956 | return "[]" |
| 957 | case 5: // negative index |
| 958 | return "[-1]" |
| 959 | case 6: // unicode key |
| 960 | return "すびほ" |
| 961 | case 7: // key with a byte requiring JSON escaping in output |
| 962 | return "a\"b" |
| 963 | case 8: // "key" (matches seed corpus) |
| 964 | return "key" |
| 965 | case 9: // "a" (common test key) |
| 966 | return "a" |
| 967 | case 10: // long ASCII key |
| 968 | return "abcdefghij" |
| 969 | default: // single ASCII char |
| 970 | return string(rune('a' + r.Intn(26))) |
| 971 | } |
| 972 | } |
| 973 | |
| 974 | // injectPathHazard randomly injects an adversarial path component into an |
| 975 | // existing path. This implements the injectEmptyKeyComponent and |