Commit Graph

6 Commits

Author SHA1 Message Date
Thomas Corbière ee67e34519 Fix lint errors (#190)
* use increment and decrement operators.

* remove unnecessary else branches.

* fix receiver names.

* remove omittable code.

* fix dot imports.
2018-04-03 12:23:28 +02:00
Emmanuel T Odeke b1c9b82531 common: NewBitArray never crashes on negatives (#170)
Fixes #169
Fixes https://github.com/tendermint/tendermint/issues/1322

The previous code was very trusting assuming that
rational actors will use this code. However, Byzantine
actors don't care and in the case of the linked issue
negative lengths can be sent to this code unfettered
having been received from a peer.

This code is essentially just a sign change from
`==`
to
`<=`

and we've gutted out that attack by being more defensive.
2018-03-18 15:17:11 +04:00
Emmanuel Odeke 763dc21393
common/BitArray: reduce fragility with methods
Fixes https://github.com/tendermint/tmlibs/issues/145
Fixes https://github.com/tendermint/tmlibs/issues/146

The code in here has been fragile when it comes to nil
but these edge cases were never tested, although they've
showed up in the wild and were only noticed because
the reporter actually read the logs otherwise
we'd have never known.

This changes covers some of these cases and adds some tests.
2018-02-06 01:12:24 -08:00
Emmanuel Odeke 84afef20f5
common: fix BitArray.Update to avoid nil dereference
Update previously only checked that the receiver was
non-nil but didn't check that the input parameter to update
"o" was non-nil causing a nil dereference in cases such as
fe632ea32a/consensus/reactor.go (L306)

Fixes https://github.com/tendermint/tendermint/issues/1169
2018-01-28 10:39:42 -07:00
Emmanuel Odeke 29471d75cb
common: no more relying on math/rand.DefaultSource
Fixes https://github.com/tendermint/tmlibs/issues/99
Updates https://github.com/tendermint/tendermint/issues/973

Removed usages of math/rand.DefaultSource in favour of our
own source that's seeded with a completely random source
and is safe for use in concurrent in multiple goroutines.
Also extend some functionality that the stdlib exposes such as
* RandPerm
* RandIntn
* RandInt31
* RandInt63

Also added an integration test whose purpose is to be run as
a consistency check to ensure that our results never repeat
hence that our internal PRNG is uniquely seeded each time.
This integration test can be triggered by setting environment variable:
`TENDERMINT_INTEGRATION_TESTS=true`
for example
```shell
TENDERMINT_INTEGRATION_TESTS=true go test
```
2017-12-14 00:18:30 -07:00
Ethan Buchman 356657a37b move all files to common/ to begin repo merge 2017-04-18 16:33:22 -04:00