aboutsummaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/utils/adt/dbsize.c14
-rw-r--r--src/backend/utils/adt/numeric.c21
2 files changed, 15 insertions, 20 deletions
diff --git a/src/backend/utils/adt/dbsize.c b/src/backend/utils/adt/dbsize.c
index 0776f3bf6cf..0e8a82d6f4d 100644
--- a/src/backend/utils/adt/dbsize.c
+++ b/src/backend/utils/adt/dbsize.c
@@ -759,23 +759,15 @@ pg_size_bytes(PG_FUNCTION_ARGS)
/* Part (4): optional exponent */
if (*endptr == 'e' || *endptr == 'E')
{
- long exponent;
char *cp;
/*
- * Note we might one day support EB units, so if what follows isn't a
- * number, just treat it all as a unit to be parsed.
+ * Note we might one day support EB units, so if what follows 'E'
+ * isn't a number, just treat it all as a unit to be parsed.
*/
- exponent = strtol(endptr + 1, &cp, 10);
+ (void) strtol(endptr + 1, &cp, 10);
if (cp > endptr + 1)
- {
- if (exponent > NUMERIC_MAX_PRECISION ||
- exponent < -NUMERIC_MAX_PRECISION)
- ereport(ERROR,
- (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("invalid size: \"%s\"", str)));
endptr = cp;
- }
}
/*
diff --git a/src/backend/utils/adt/numeric.c b/src/backend/utils/adt/numeric.c
index 2fbdfe07582..620226cea11 100644
--- a/src/backend/utils/adt/numeric.c
+++ b/src/backend/utils/adt/numeric.c
@@ -753,10 +753,6 @@ numeric_recv(PG_FUNCTION_ARGS)
init_var(&value);
len = (uint16) pq_getmsgint(buf, sizeof(uint16));
- if (len < 0 || len > NUMERIC_MAX_PRECISION + NUMERIC_MAX_RESULT_SCALE)
- ereport(ERROR,
- (errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
- errmsg("invalid length in external \"numeric\" value")));
alloc_var(&value, len);
@@ -5456,12 +5452,19 @@ set_var_from_str(const char *str, const char *cp, NumericVar *dest)
errmsg("invalid input syntax for type numeric: \"%s\"",
str)));
cp = endptr;
- if (exponent > NUMERIC_MAX_PRECISION ||
- exponent < -NUMERIC_MAX_PRECISION)
+
+ /*
+ * At this point, dweight and dscale can't be more than about
+ * INT_MAX/2 due to the MaxAllocSize limit on string length, so
+ * constraining the exponent similarly should be enough to prevent
+ * integer overflow in this function. If the value is too large to
+ * fit in storage format, make_result() will complain about it later;
+ * for consistency use the same ereport errcode/text as make_result().
+ */
+ if (exponent >= INT_MAX / 2 || exponent <= -(INT_MAX / 2))
ereport(ERROR,
- (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
- errmsg("invalid input syntax for type numeric: \"%s\"",
- str)));
+ (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
+ errmsg("value overflows numeric format")));
dweight += (int) exponent;
dscale -= (int) exponent;
if (dscale < 0)