git.postgresql.org Git - postgresql.git/commitdiff

git projects / postgresql.git / commitdiff
? search:
summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 203749a)
Disallow NaN as a value for floating-point GUCs.
2019年3月10日 16:58:51 +0000 (12:58 -0400)
2019年3月10日 16:59:16 +0000 (12:59 -0400)
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


diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index bb6052ab15a6aa236b4695e7b5c74435ff72e416..386f6b135f4d09c1a3efc8001fa59c50b51943ba 100644 (file)
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -6149,6 +6149,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 b0d735114511a7374689e49dcd44b08f14d5ce91..5c57a6656f55f93b2c66cbf3853374a736bf120e 100644 (file)
--- a/src/test/regress/expected/guc.out
+++ b/src/test/regress/expected/guc.out
@@ -506,6 +506,13 @@ 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)
+SET geqo_selection_bias TO '-infinity';
+ERROR: -Infinity is outside the valid range for parameter "geqo_selection_bias" (1.5 .. 2)
--
-- Test DISCARD TEMP
--
diff --git a/src/test/regress/sql/guc.sql b/src/test/regress/sql/guc.sql
index 3b854ac4963f8ca404218c38574768db6f3621b8..6d3fca933580c559bc36f8472a41679d328ab2f1 100644 (file)
--- a/src/test/regress/sql/guc.sql
+++ b/src/test/regress/sql/guc.sql
@@ -144,6 +144,11 @@ 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';
+SET geqo_selection_bias TO '-infinity';
+
--
-- Test DISCARD TEMP
--
This is the main PostgreSQL git repository.
RSS Atom

AltStyle によって変換されたページ (->オリジナル) /