postgres.git / summary / log / commit / refs
commit d8f8183c04671b0ffe26ae6f8aee9e50df5fff1e
Author: Tom Lane <tgl@sss.pgh.pa.us>
Date: Sun Mar 10 16:58:52 2019 +0000
First released in: 12.0, 9.4.22, 9.5.17, 9.6.13, 10.8, 11.3
Disallow NaN as a value for floating-point GUCs.
None of the code that uses GUC values is really prepared for them to
hold NaN, but parse_real() didn't have any defense against accepting
such a value. Treat it the same as a syntax error.
I haven't attempted to analyze the exact consequences of setting any
of the float GUCs to NaN, but since they're quite unlikely to be good,
this seems like a back-patchable bug fix.
Note: we don't need an explicit test for +-Infinity because those will
be rejected by existing range checks. I added a regression test for
that in HEAD, but not older branches because the spelling of the value
in the error message will be platform-dependent in branches where we
don't always use port/snprintf.c.
Discussion: https://postgr.es/m/1798.1552165479@sss.pgh.pa.us
src/backend/utils/misc/guc.c | 4 ++++
src/test/regress/expected/guc.out | 5 +++++
src/test/regress/sql/guc.sql | 4 ++++
3 files changed, 13 insertions(+)
diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index 427d807ada1..0c9ed0908f6 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -5327,6 +5327,10 @@ parse_real(const char *value, double *result)
if (endptr == value || errno == ERANGE)
return false;
+ /* reject NaN (infinities will fail range checks later) */
+ if (isnan(val))
+ return false;
+
/* allow whitespace after number */
while (isspace((unsigned char) *endptr))
endptr++;
diff --git a/src/test/regress/expected/guc.out b/src/test/regress/expected/guc.out
index 4f0065cb7ef..bca2738c0dc 100644
--- a/src/test/regress/expected/guc.out
+++ b/src/test/regress/expected/guc.out
@@ -506,6 +506,11 @@ SELECT '2006-08-13 12:34:56'::timestamptz;
Sun Aug 13 12:34:56 2006 PDT
(1 row)
+-- Test some simple error cases
+SET seq_page_cost TO 'NaN';
+ERROR: parameter "seq_page_cost" requires a numeric value
+SET vacuum_cost_delay TO '10s';
+ERROR: 10000 is outside the valid range for parameter "vacuum_cost_delay" (0 .. 100)
--
-- Test DISCARD TEMP
--
diff --git a/src/test/regress/sql/guc.sql b/src/test/regress/sql/guc.sql
index 3de8a6b55d6..a99cd5f78a0 100644
--- a/src/test/regress/sql/guc.sql
+++ b/src/test/regress/sql/guc.sql
@@ -144,6 +144,10 @@ RESET datestyle;
SHOW datestyle;
SELECT '2006-08-13 12:34:56'::timestamptz;
+-- Test some simple error cases
+SET seq_page_cost TO 'NaN';
+SET vacuum_cost_delay TO '10s';
+
--
-- Test DISCARD TEMP
--
[parent: a2c59a28c738]