Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit bc2232f

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 7d7de6d commit bc2232f

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

src/backend/utils/misc/guc.c

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

5850+
/* reject NaN (infinities will fail range checks later) */
5851+
if (isnan(val))
5852+
return false;
5853+
58505854
/* allow whitespace after number */
58515855
while (isspace((unsigned char) *endptr))
58525856
endptr++;

src/test/regress/expected/guc.out

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,11 @@ 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)
509514
--
510515
-- Test DISCARD TEMP
511516
--

src/test/regress/sql/guc.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ 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+
147151
--
148152
-- Test DISCARD TEMP
149153
--

0 commit comments

Comments
 (0)