perf: Cap RANDOM_STRING_N to 8182 (#1193)

This commit is contained in:
TwiN
2025-08-11 09:36:55 -04:00
committed by GitHub
parent 3ebed01b4c
commit daf67dc1e6
2 changed files with 4 additions and 1 deletions

View File

@@ -295,7 +295,7 @@ You may use the following placeholders in the body (`endpoints[].body`):
- `[ENDPOINT_GROUP]` (resolved from `endpoints[].group`)
- `[ENDPOINT_URL]` (resolved from `endpoints[].url`)
- `[LOCAL_ADDRESS]` (resolves to the local IP and port like `192.0.2.1:25` or `[2001:db8::1]:80`)
- `[RANDOM_STRING_N]` (resolves to a random string of numbers and letters of length N)
- `[RANDOM_STRING_N]` (resolves to a random string of numbers and letters of length N (max: 8192))
### External Endpoints

View File

@@ -344,6 +344,9 @@ func (e *Endpoint) getParsedBody() string {
if err == nil {
body = randRegex.ReplaceAllStringFunc(body, func(match string) string {
n, _ := strconv.Atoi(match[15 : len(match)-1])
if n > 8192 {
n = 8192 // Limit the length of the random string to 8192 bytes to avoid excessive memory usage
}
const availableCharacterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
b := make([]byte, n)
for i := range b {