(limit int)
| 172 | } |
| 173 | |
| 174 | func decRegexProgramSizeLimit(limit int) InterpretableDecoratorV2 { |
| 175 | return func(i InterpretableV2) (InterpretableV2, error) { |
| 176 | if limit <= 0 { |
| 177 | return i, nil |
| 178 | } |
| 179 | call, ok := i.(InterpretableCall) |
| 180 | if !ok { |
| 181 | return i, nil |
| 182 | } |
| 183 | if !isRegexFunction(call.Function(), call.OverloadID()) || len(call.Args()) < 2 { |
| 184 | return i, nil |
| 185 | } |
| 186 | regexArg := call.Args()[1] |
| 187 | if constVal, isConst := regexArg.(InterpretableConst); isConst { |
| 188 | if pattern, ok := constVal.Value().(types.String); ok { |
| 189 | sz, err := types.RegexProgramSize(string(pattern)) |
| 190 | if err != nil { |
| 191 | return i, nil |
| 192 | } |
| 193 | if sz > limit { |
| 194 | return nil, fmt.Errorf("regex program size %d exceeds limit of %d", sz, limit) |
| 195 | } |
| 196 | } |
| 197 | return i, nil |
| 198 | } |
| 199 | return ®exLimitCall{InterpretableCall: call, limit: limit}, nil |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | func isRegexFunction(fn, overload string) bool { |
| 204 | switch fn { |
no test coverage detected