Skip to content

Commit ac75959

Browse files
committed
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
1 parent 203749a commit ac75959

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

src/backend/utils/misc/guc.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6149,6 +6149,10 @@ parse_real(const char *value, double *result)
61496149
if (endptr == value || errno == ERANGE)
61506150
return false;
61516151

6152+
/* reject NaN (infinities will fail range checks later) */
6153+
if (isnan(val))
6154+
return false;
6155+
61526156
/* allow whitespace after number */
61536157
while (isspace((unsigned char) *endptr))
61546158
endptr++;

src/test/regress/expected/guc.out

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,13 @@ SELECT '2006-08-13 12:34:56'::timestamptz;
506506
Sun Aug 13 12:34:56 2006 PDT
507507
(1 row)
508508

509+
-- Test some simple error cases
510+
SET seq_page_cost TO 'NaN';
511+
ERROR: parameter "seq_page_cost" requires a numeric value
512+
SET vacuum_cost_delay TO '10s';
513+
ERROR: 10000 is outside the valid range for parameter "vacuum_cost_delay" (0 .. 100)
514+
SET geqo_selection_bias TO '-infinity';
515+
ERROR: -Infinity is outside the valid range for parameter "geqo_selection_bias" (1.5 .. 2)
509516
--
510517
-- Test DISCARD TEMP
511518
--

src/test/regress/sql/guc.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@ RESET datestyle;
144144
SHOW datestyle;
145145
SELECT '2006-08-13 12:34:56'::timestamptz;
146146

147+
-- Test some simple error cases
148+
SET seq_page_cost TO 'NaN';
149+
SET vacuum_cost_delay TO '10s';
150+
SET geqo_selection_bias TO '-infinity';
151+
147152
--
148153
-- Test DISCARD TEMP
149154
--

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy