all repos — captcha @ 1c861dea7609d13926fbbcf6faae8c078604a702

Go package captcha implements generation and verification of image and audio CAPTCHAs.

Fix modulo bias in randomBytesMod.

See
https://github.com/dchest/uniuri/commit/2e215562f605dacd124f15eb89523bdc32da3a41
Dmitry Chestnykh dmitry@codingrobots.com
Fri, 24 Apr 2015 15:21:27 +0200
commit

1c861dea7609d13926fbbcf6faae8c078604a702

parent

e965f48e07b0fe1f10061c0eade5075266cd6cb0

1 files changed, 8 insertions(+), 1 deletions(-)

jump to
M random.gorandom.go

@@ -72,8 +72,14 @@

// randomBytesMod returns a byte slice of the given length, where each byte is // a random number modulo mod. func randomBytesMod(length int, mod byte) (b []byte) { + if length == 0 { + return nil + } + if mod == 0 { + panic("captcha: bad mod argument for randomBytesMod") + } + maxrb := 255 - byte(256 % int(mod)) b = make([]byte, length) - maxrb := byte(256 - (256 % int(mod))) i := 0 for { r := randomBytes(length + (length / 4))

@@ -89,6 +95,7 @@ return

} } } + } // randomId returns a new random id string.