]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Disallow NaN as a value for floating-point GUCs.
authorTom Lane <tgl@sss.pgh.pa.us>
Sun, 10 Mar 2019 16:58:52 +0000 (12:58 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Sun, 10 Mar 2019 16:58:52 +0000 (12:58 -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

src/backend/utils/misc/guc.c
src/test/regress/expected/guc.out
src/test/regress/sql/guc.sql

index 9a7a0b045a9322ad27faa516697a722d29bffeee..3051c9cf8e4f8d803d7d4cea1437bdb2453ad522 100644 (file)
@@ -5847,6 +5847,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++;
index 43ac5f5f11ccf27cf348e4d154b1391dcac5a592..4afbd3c4dca478a468e6ad418f6c1e3989f58152 100644 (file)
@@ -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
 --
index 23e50297800f9164ced75d6f7e8c457f41c21821..fa6a9d6c340978fd27c39a319361d9b5df7250f9 100644 (file)
@@ -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
 --