{"record":{"id":"077ed95215545d5c","repo":"shadow1ng/fscan","slug":"randomint-max-d-must-be-greater-than-min-d","errorCode":null,"errorMessage":"randomInt: max(%d) must be greater than min(%d)","messagePattern":"randomInt: max\\((.+?)\\) must be greater than min\\((.+?)\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"webscan/lib/eval_random.go","lineNumber":108,"sourceCode":"\t\t\tOperator: \"randomString_int\",\n\t\t\tUnary: func(value ref.Val) ref.Val {\n\t\t\t\tn, ok := value.(types.Int)\n\t\t\t\tif !ok {\n\t\t\t\t\treturn types.ValOrErr(value, \"unexpected type '%v' passed to randomString\", value.Type())\n\t\t\t\t}\n\t\t\t\tlength, err := validateRandomStringLength(n)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn types.NewErr(\"%v\", err)\n\t\t\t\t}\n\t\t\t\treturn types.String(randomString(length))\n\t\t\t},\n\t\t},\n\t}\n}\n\nfunc randomIntSpan(min, max int64) (int64, error) {\n\tif max <= min {\n\t\treturn 0, fmt.Errorf(\"randomInt: max(%d) must be greater than min(%d)\", max, min)\n\t}\n\tconst maxInt64 = int64(^uint64(0) >> 1)\n\tif min < 0 && max > maxInt64+min {\n\t\treturn 0, fmt.Errorf(\"randomInt: range too large\")\n\t}\n\treturn max - min, nil\n}\n\nfunc validateRandomStringLength(n types.Int) (int, error) {\n\tif n < 0 || n > maxRandomStringLength {\n\t\treturn 0, fmt.Errorf(\"random string length must be between 0 and %d\", maxRandomStringLength)\n\t}\n\treturn int(n), nil\n}\n","sourceCodeStart":90,"sourceCodeEnd":123,"githubUrl":"https://github.com/shadow1ng/fscan/blob/95cc12e753bf43de7004e5aef42a9ffba3934303/webscan/lib/eval_random.go#L90-L123","documentation":"randomIntSpan validates the min/max arguments for the randomInt expression function. It requires max to be strictly greater than min; otherwise it returns this descriptive error. This guards against nonsensical ranges where no integer can be produced.","triggerScenarios":"Calling randomInt(min, max) (or expression randomInt(...) in a POC) with max <= min, e.g. randomInt(10, 10) or randomInt(5, 3).","commonSituations":"POC templates where min/max are computed from variables that end up equal or inverted; typos swapping the arguments; dynamically generated ranges that degenerate to a single value.","solutions":["Ensure max is strictly greater than min before calling randomInt.","If min and max are equal by design, decide the value yourself instead of calling randomInt.","Swap the arguments if they were accidentally reversed."],"exampleFix":"// before\nv, err := randomIntSpan(max, min)\n\n// after\nif min >= max { min, max = max, min }\nv, err := randomIntSpan(min, max)","handlingStrategy":"validation","validationCode":"if min >= max {\n    return errors.New(\"randomInt: max must be greater than min\")\n}","typeGuard":null,"tryCatchPattern":"v, err := randomIntSpan(min, max)\nif err != nil {\n    return fmt.Errorf(\"bad range [%d,%d): %w\", min, max, err)\n}","preventionTips":["Assert max > min wherever min/max come from variables or user input.","Swap arguments if ordering is ambiguous.","Handle the equal case as a deterministic value instead of a random call."],"tags":["validation","arguments","random","expression-eval"],"backgroundTag":"invalid-argument-value","analyzedSha":"95cc12e753bf43de7004e5aef42a9ffba3934303","analyzedAt":"2026-09-06T17:07:30.094Z","contentChangedAt":"2026-09-06T17:07:30.094Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}