From 5a1243ff42f58d316601c249f2542faf5a4931b2 Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Sat, 15 Apr 2017 16:48:44 -0600 Subject: [PATCH] context: Fix computation for random length of random string --- caddyhttp/httpserver/context.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/caddyhttp/httpserver/context.go b/caddyhttp/httpserver/context.go index b19ce879f..52a5b556f 100644 --- a/caddyhttp/httpserver/context.go +++ b/caddyhttp/httpserver/context.go @@ -367,12 +367,12 @@ func (c Context) RandomString(minLen, maxLen int) string { letterIdxMax = 63 / letterIdxBits // # of letter indices fitting in 63 bits ) - if minLen < 0 || maxLen < 0 || maxLen <= minLen { + if minLen < 0 || maxLen < 0 || maxLen < minLen { return "" } src := rand.NewSource(time.Now().UnixNano()) - n := rand.Intn(maxLen-minLen) + minLen // choose actual length + n := rand.Intn(maxLen-minLen+1) + minLen // choose actual length b := make([]byte, n) for i, cache, remain := n-1, src.Int63(), letterIdxMax; i >= 0; { if remain == 0 {