Skip to content

Commit 11c794f

Browse files
committed
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.
1 parent 509303a commit 11c794f

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

src/backend/access/common/reloptions.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/common/reloptions.c,v 1.10 2008/04/17 21:37:28 alvherre Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/common/reloptions.c,v 1.11 2008/07/23 17:29:53 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -21,6 +21,7 @@
2121
#include "nodes/makefuncs.h"
2222
#include "utils/array.h"
2323
#include "utils/builtins.h"
24+
#include "utils/guc.h"
2425
#include "utils/rel.h"
2526

2627

@@ -287,7 +288,7 @@ default_reloptions(Datum reloptions, bool validate,
287288
{
288289
static const char *const default_keywords[1] = {"fillfactor"};
289290
char *values[1];
290-
int32 fillfactor;
291+
int fillfactor;
291292
StdRdOptions *result;
292293

293294
parseRelOptions(reloptions, 1, default_keywords, values, validate);
@@ -300,7 +301,16 @@ default_reloptions(Datum reloptions, bool validate,
300301
if (values[0] == NULL)
301302
return NULL;
302303

303-
fillfactor = pg_atoi(values[0], sizeof(int32), 0);
304+
if (!parse_int(values[0], &fillfactor, 0, NULL))
305+
{
306+
if (validate)
307+
ereport(ERROR,
308+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
309+
errmsg("fillfactor must be an integer: \"%s\"",
310+
values[0])));
311+
return NULL;
312+
}
313+
304314
if (fillfactor < minFillfactor || fillfactor > 100)
305315
{
306316
if (validate)

src/backend/utils/misc/guc.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Written by Peter Eisentraut <peter_e@gmx.net>.
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.464 2008/07/10 22:08:17 tgl Exp $
13+
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.465 2008/07/23 17:29:53 tgl Exp $
1414
*
1515
*--------------------------------------------------------------------
1616
*/
@@ -4115,7 +4115,7 @@ parse_bool(const char *value, bool *result)
41154115
* If not okay and hintmsg is not NULL, *hintmsg is set to a suitable
41164116
* HINT message, or NULL if no hint provided.
41174117
*/
4118-
static bool
4118+
bool
41194119
parse_int(const char *value, int *result, int flags, const char **hintmsg)
41204120
{
41214121
int64 val;
@@ -4322,7 +4322,7 @@ parse_int(const char *value, int *result, int flags, const char **hintmsg)
43224322
* If the string parses okay, return true, else false.
43234323
* If okay and result is not NULL, return the value in *result.
43244324
*/
4325-
static bool
4325+
bool
43264326
parse_real(const char *value, double *result)
43274327
{
43284328
double val;

src/include/utils/guc.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Copyright (c) 2000-2008, PostgreSQL Global Development Group
88
* Written by Peter Eisentraut <peter_e@gmx.net>.
99
*
10-
* $PostgreSQL: pgsql/src/include/utils/guc.h,v 1.97 2008/06/30 22:10:43 momjian Exp $
10+
* $PostgreSQL: pgsql/src/include/utils/guc.h,v 1.98 2008/07/23 17:29:53 tgl Exp $
1111
*--------------------------------------------------------------------
1212
*/
1313
#ifndef GUC_H
@@ -224,6 +224,9 @@ extern void AtEOXact_GUC(bool isCommit, int nestLevel);
224224
extern void BeginReportingGUCOptions(void);
225225
extern void ParseLongOption(const char *string, char **name, char **value);
226226
extern bool parse_bool(const char *value, bool *result);
227+
extern bool parse_int(const char *value, int *result, int flags,
228+
const char **hintmsg);
229+
extern bool parse_real(const char *value, double *result);
227230
extern bool set_config_option(const char *name, const char *value,
228231
GucContext context, GucSource source,
229232
GucAction action, bool changeVal);

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