diff options
author | Michael Paquier <michael@paquier.xyz> | 2019-08-05 15:35:16 +0900 |
---|---|---|
committer | Michael Paquier <michael@paquier.xyz> | 2019-08-05 15:35:16 +0900 |
commit | a76cfba663ceab79b891cc81a5f941051755b3b0 (patch) | |
tree | 9aaaf52bc2d59eb507d4562ec5f9e6c039122809 /src/backend/utils/adt/numeric.c | |
parent | 05ba8370b8e4b5c8f3dd51986b9fdeb43fed5610 (diff) | |
download | postgresql-a76cfba663ceab79b891cc81a5f941051755b3b0.tar.gz postgresql-a76cfba663ceab79b891cc81a5f941051755b3b0.zip |
Add safeguards in LSN, numeric and float calculation for custom errors
Those data types use parsing and/or calculation wrapper routines which
can generate some generic error messages in the event of a failure. The
caller of these routines can also pass a pointer variable settable by
the routine to track if an error has happened, letting the caller decide
what to do in the event of an error and what error message to generate.
Those routines have been slacking the initialization of the tracking
flag, which can be confusing when reading the code, so add some
safeguards against calls of these parsing routines which could lead to a
dubious result.
The LSN parsing gains an assertion to make sure that the tracking flag
is set, while numeric and float paths initialize the flag to a saner
state.
Author: Jeevan Ladhe
Reviewed-by: Álvaro Herrera, Michael Paquier
Discussion: https://postgr.es/m/CAOgcT0NOM9oR0Hag_3VpyW0uF3iCU=BDUFSPfk9JrWXRcWQHqw@mail.gmail.com
Diffstat (limited to 'src/backend/utils/adt/numeric.c')
-rw-r--r-- | src/backend/utils/adt/numeric.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/backend/utils/adt/numeric.c b/src/backend/utils/adt/numeric.c index 201784bbf66..a00db3ce7a8 100644 --- a/src/backend/utils/adt/numeric.c +++ b/src/backend/utils/adt/numeric.c @@ -2605,6 +2605,9 @@ numeric_div_opt_error(Numeric num1, Numeric num2, bool *have_error) Numeric res; int rscale; + if (have_error) + *have_error = false; + /* * Handle NaN */ @@ -2721,6 +2724,9 @@ numeric_mod_opt_error(Numeric num1, Numeric num2, bool *have_error) NumericVar arg2; NumericVar result; + if (have_error) + *have_error = false; + if (NUMERIC_IS_NAN(num1) || NUMERIC_IS_NAN(num2)) return make_result(&const_nan); @@ -3207,6 +3213,9 @@ numeric_int4_opt_error(Numeric num, bool *have_error) NumericVar x; int32 result; + if (have_error) + *have_error = false; + /* XXX would it be better to return NULL? */ if (NUMERIC_IS_NAN(num)) { @@ -6249,6 +6258,9 @@ make_result_opt_error(const NumericVar *var, bool *have_error) int n; Size len; + if (have_error) + *have_error = false; + if (sign == NUMERIC_NAN) { result = (Numeric) palloc(NUMERIC_HDRSZ_SHORT); |