diff options
| author | Russell Yanofsky <[email protected]> | 2017-02-13 13:41:02 -0500 |
|---|---|---|
| committer | Russell Yanofsky <[email protected]> | 2018-03-15 18:57:55 -0500 |
| commit | 499d95e278f34790660a2b9baf5525e0def1485a (patch) | |
| tree | f95140f9f7ba7344345e96c5da618d48e5b5d44b /src/chain.h | |
| parent | Merge #12683: Fix more constness violations in serialization code (diff) | |
| download | discoin-499d95e278f34790660a2b9baf5525e0def1485a.tar.xz discoin-499d95e278f34790660a2b9baf5525e0def1485a.zip | |
Add static_assert to prevent VARINT(<signed value>)
Using VARINT with signed types is dangerous because negative values will appear
to serialize correctly, but then deserialize as positive values mod 128.
This commit changes the VARINT macro to trigger an error by default if called
with an signed value, and updates broken uses of VARINT to pass a special flag
that lets them keep working with no change in behavior.
Diffstat (limited to 'src/chain.h')
| -rw-r--r-- | src/chain.h | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/chain.h b/src/chain.h index 3728f768c..757840bb2 100644 --- a/src/chain.h +++ b/src/chain.h @@ -91,7 +91,7 @@ struct CDiskBlockPos template <typename Stream, typename Operation> inline void SerializationOp(Stream& s, Operation ser_action) { - READWRITE(VARINT(nFile)); + READWRITE(VARINT(nFile, VarIntMode::NONNEGATIVE_SIGNED)); READWRITE(VARINT(nPos)); } @@ -386,13 +386,13 @@ public: inline void SerializationOp(Stream& s, Operation ser_action) { int _nVersion = s.GetVersion(); if (!(s.GetType() & SER_GETHASH)) - READWRITE(VARINT(_nVersion)); + READWRITE(VARINT(_nVersion, VarIntMode::NONNEGATIVE_SIGNED)); - READWRITE(VARINT(nHeight)); + READWRITE(VARINT(nHeight, VarIntMode::NONNEGATIVE_SIGNED)); READWRITE(VARINT(nStatus)); READWRITE(VARINT(nTx)); if (nStatus & (BLOCK_HAVE_DATA | BLOCK_HAVE_UNDO)) - READWRITE(VARINT(nFile)); + READWRITE(VARINT(nFile, VarIntMode::NONNEGATIVE_SIGNED)); if (nStatus & BLOCK_HAVE_DATA) READWRITE(VARINT(nDataPos)); if (nStatus & BLOCK_HAVE_UNDO) |