diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2008-07-23 17:29:53 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2008-07-23 17:29:53 +0000 |
commit | 11c794f2249ba6b1d890da309e26e0ddff8bc60c (patch) | |
tree | 40d0a6fdad1bb8fd5350d4034ca7feebb312f416 /src/backend/access/common/reloptions.c | |
parent | 509303a597a1688e6c2230c83634a75f872d270c (diff) | |
download | postgresql-11c794f2249ba6b1d890da309e26e0ddff8bc60c.tar.gz postgresql-11c794f2249ba6b1d890da309e26e0ddff8bc60c.zip |
Use guc.c's parse_int() instead of pg_atoi() to parse fillfactor in
default_reloptions(). The previous coding was really a bug because pg_atoi()
will always throw elog on bad input data, whereas default_reloptions is not
supposed to complain about bad input unless its validate parameter is true.
Right now you could only expose the problem by hand-modifying
pg_class.reloptions into an invalid state, so it doesn't seem worth
back-patching; but we should get it right in HEAD because there might be other
situations in future. Noted while studying GIN fast-update patch.
Diffstat (limited to 'src/backend/access/common/reloptions.c')
-rw-r--r-- | src/backend/access/common/reloptions.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/backend/access/common/reloptions.c b/src/backend/access/common/reloptions.c index 8822535998f..eb662f295f9 100644 --- a/src/backend/access/common/reloptions.c +++ b/src/backend/access/common/reloptions.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/access/common/reloptions.c,v 1.10 2008/04/17 21:37:28 alvherre Exp $ + * $PostgreSQL: pgsql/src/backend/access/common/reloptions.c,v 1.11 2008/07/23 17:29:53 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -21,6 +21,7 @@ #include "nodes/makefuncs.h" #include "utils/array.h" #include "utils/builtins.h" +#include "utils/guc.h" #include "utils/rel.h" @@ -287,7 +288,7 @@ default_reloptions(Datum reloptions, bool validate, { static const char *const default_keywords[1] = {"fillfactor"}; char *values[1]; - int32 fillfactor; + int fillfactor; StdRdOptions *result; parseRelOptions(reloptions, 1, default_keywords, values, validate); @@ -300,7 +301,16 @@ default_reloptions(Datum reloptions, bool validate, if (values[0] == NULL) return NULL; - fillfactor = pg_atoi(values[0], sizeof(int32), 0); + if (!parse_int(values[0], &fillfactor, 0, NULL)) + { + if (validate) + ereport(ERROR, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("fillfactor must be an integer: \"%s\"", + values[0]))); + return NULL; + } + if (fillfactor < minFillfactor || fillfactor > 100) { if (validate) |