From 84dd5c27288e192277a1edb409c931cc72129718 Mon Sep 17 00:00:00 2001 From: Stefan Thomas Date: Wed, 30 Jan 2013 17:58:40 +0100 Subject: [PATCH] Add check to prevent negative zero. We want a canonical encoding for zero which is 0x4000000000000000 i.e. "positive zero". So we want to disallow the alternative encoding 0x0000000000000000 i.e. "negative zero". --- src/cpp/ripple/Amount.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cpp/ripple/Amount.cpp b/src/cpp/ripple/Amount.cpp index ceca79163..7d5049482 100644 --- a/src/cpp/ripple/Amount.cpp +++ b/src/cpp/ripple/Amount.cpp @@ -570,12 +570,14 @@ STAmount* STAmount::construct(SerializerIterator& sit, SField::ref name) { // native if ((value & cPosNative) != 0) return new STAmount(name, value & ~cPosNative, false); // positive + else if (value == 0) + throw std::runtime_error("negative zero is not canonical"); return new STAmount(name, value, true); // negative } uint160 uCurrencyID = sit.get160(); if (!uCurrencyID) - throw std::runtime_error("invalid native currency"); + throw std::runtime_error("invalid non-native currency"); uint160 uIssuerID = sit.get160();