From 62d09ccc103ea364738137ac6b2e6d82dfef4ff3 Mon Sep 17 00:00:00 2001 From: Sad Pencil Date: Mon, 10 Aug 2020 16:42:14 +0800 Subject: [PATCH] libs/rand: fix "out-of-memory" error on unexpected argument (#5215) --- CHANGELOG_PENDING.md | 1 + libs/rand/random.go | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/CHANGELOG_PENDING.md b/CHANGELOG_PENDING.md index 02656e1c4..71f5cfab8 100644 --- a/CHANGELOG_PENDING.md +++ b/CHANGELOG_PENDING.md @@ -19,3 +19,4 @@ Friendly reminder, we have a [bug bounty program](https://hackerone.com/tendermi - [evidence] [\#5170](https://github.com/tendermint/tendermint/pull/5170) change abci evidence time to the time the infraction happened not the time the evidence was committed on the block (@cmwaters) - [node] Don't attempt fast sync when the ABCI application specifies ourself as the only validator via `InitChain` (@erikgrinaker) +- [libs/rand] [\#5215](https://github.com/tendermint/tendermint/pull/5215) Fix out-of-memory error on unexpected argument of Str() (@SadPencil) diff --git a/libs/rand/random.go b/libs/rand/random.go index b15e2561f..41d04a440 100644 --- a/libs/rand/random.go +++ b/libs/rand/random.go @@ -149,6 +149,10 @@ func (r *Rand) Seed(seed int64) { // Str constructs a random alphanumeric string of given length. func (r *Rand) Str(length int) string { + if length <= 0 { + return "" + } + chars := []byte{} MAIN_LOOP: for {