fix #5167
This commit is contained in:
parent
9236f3aaa0
commit
84998f9d05
@ -1,3 +1,6 @@
|
|||||||
|
Thu Nov 2 17:39:40 CET 2017
|
||||||
|
Limit amount values to 2^53 as we always wanted (#5167). -CG
|
||||||
|
|
||||||
Thu Nov 2 16:50:46 CET 2017
|
Thu Nov 2 16:50:46 CET 2017
|
||||||
Fixing serious bug in reserve balance calculations, as
|
Fixing serious bug in reserve balance calculations, as
|
||||||
fees were not always properly included in the summation. -CG
|
fees were not always properly included in the summation. -CG
|
||||||
|
@ -29,6 +29,25 @@
|
|||||||
#endif
|
#endif
|
||||||
#include <gcrypt.h>
|
#include <gcrypt.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maximum legal 'value' for an amount, based on IEEE double (for JavaScript compatibility).
|
||||||
|
*/
|
||||||
|
#define MAX_AMOUNT_VALUE (1LLU << 53)
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set @a a to "invalid".
|
||||||
|
*
|
||||||
|
* @param a amount to set to invalid
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
invalidate (struct TALER_Amount *a)
|
||||||
|
{
|
||||||
|
memset (a,
|
||||||
|
0,
|
||||||
|
sizeof (struct TALER_Amount));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse money amount description, in the format "A:B.C".
|
* Parse money amount description, in the format "A:B.C".
|
||||||
@ -48,9 +67,7 @@ TALER_string_to_amount (const char *str,
|
|||||||
const char *colon;
|
const char *colon;
|
||||||
const char *value;
|
const char *value;
|
||||||
|
|
||||||
memset (denom,
|
invalidate (denom);
|
||||||
0,
|
|
||||||
sizeof (struct TALER_Amount));
|
|
||||||
/* skip leading whitespace */
|
/* skip leading whitespace */
|
||||||
while (isspace( (unsigned char) str[0]))
|
while (isspace( (unsigned char) str[0]))
|
||||||
str++;
|
str++;
|
||||||
@ -139,6 +156,12 @@ TALER_string_to_amount (const char *str,
|
|||||||
b /= 10;
|
b /= 10;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
if (denom->value > MAX_AMOUNT_VALUE)
|
||||||
|
{
|
||||||
|
/* too large to be legal */
|
||||||
|
invalidate (denom);
|
||||||
|
return GNUNET_SYSERR;
|
||||||
|
}
|
||||||
return GNUNET_OK;
|
return GNUNET_OK;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
@ -237,20 +260,6 @@ TALER_amount_get_zero (const char *cur,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set @a a to "invalid".
|
|
||||||
*
|
|
||||||
* @param a amount to set to invalid
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
invalidate (struct TALER_Amount *a)
|
|
||||||
{
|
|
||||||
memset (a,
|
|
||||||
0,
|
|
||||||
sizeof (struct TALER_Amount));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test if the given amount is valid.
|
* Test if the given amount is valid.
|
||||||
*
|
*
|
||||||
@ -472,6 +481,12 @@ TALER_amount_add (struct TALER_Amount *sum,
|
|||||||
invalidate (sum);
|
invalidate (sum);
|
||||||
return GNUNET_SYSERR;
|
return GNUNET_SYSERR;
|
||||||
}
|
}
|
||||||
|
if (res.value > MAX_AMOUNT_VALUE)
|
||||||
|
{
|
||||||
|
/* too large to be legal */
|
||||||
|
invalidate (sum);
|
||||||
|
return GNUNET_SYSERR;
|
||||||
|
}
|
||||||
res.fraction = n1.fraction + n2.fraction;
|
res.fraction = n1.fraction + n2.fraction;
|
||||||
if (GNUNET_SYSERR ==
|
if (GNUNET_SYSERR ==
|
||||||
TALER_amount_normalize (&res))
|
TALER_amount_normalize (&res))
|
||||||
|
Loading…
Reference in New Issue
Block a user