Skip to content

Commit daf67dc

Browse files
authored
perf: Cap RANDOM_STRING_N to 8182 (#1193)
1 parent 3ebed01 commit daf67dc

2 files changed

Lines changed: 4 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ You may use the following placeholders in the body (`endpoints[].body`):
295295
- `[ENDPOINT_GROUP]` (resolved from `endpoints[].group`)
296296
- `[ENDPOINT_URL]` (resolved from `endpoints[].url`)
297297
- `[LOCAL_ADDRESS]` (resolves to the local IP and port like `192.0.2.1:25` or `[2001:db8::1]:80`)
298-
- `[RANDOM_STRING_N]` (resolves to a random string of numbers and letters of length N)
298+
- `[RANDOM_STRING_N]` (resolves to a random string of numbers and letters of length N (max: 8192))
299299

300300

301301
### External Endpoints

config/endpoint/endpoint.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,9 @@ func (e *Endpoint) getParsedBody() string {
344344
if err == nil {
345345
body = randRegex.ReplaceAllStringFunc(body, func(match string) string {
346346
n, _ := strconv.Atoi(match[15 : len(match)-1])
347+
if n > 8192 {
348+
n = 8192 // Limit the length of the random string to 8192 bytes to avoid excessive memory usage
349+
}
347350
const availableCharacterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
348351
b := make([]byte, n)
349352
for i := range b {

0 commit comments

Comments
 (0)