Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit11c794f

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 notsupposed to complain about bad input unless its validate parameter is true.Right now you could only expose the problem by hand-modifyingpg_class.reloptions into an invalid state, so it doesn't seem worthback-patching; but we should get it right in HEAD because there might be othersituations in future. Noted while studying GIN fast-update patch.
1 parent509303a commit11c794f

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
staticconstchar*constdefault_keywords[1]= {"fillfactor"};
289290
char*values[1];
290-
int32fillfactor;
291+
intfillfactor;
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
returnNULL;
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+
returnNULL;
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-
staticbool
4118+
bool
41194119
parse_int(constchar*value,int*result,intflags,constchar**hintmsg)
41204120
{
41214121
int64val;
@@ -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-
staticbool
4325+
bool
43264326
parse_real(constchar*value,double*result)
43274327
{
43284328
doubleval;

‎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
#ifndefGUC_H
@@ -224,6 +224,9 @@ extern void AtEOXact_GUC(bool isCommit, int nestLevel);
224224
externvoidBeginReportingGUCOptions(void);
225225
externvoidParseLongOption(constchar*string,char**name,char**value);
226226
externboolparse_bool(constchar*value,bool*result);
227+
externboolparse_int(constchar*value,int*result,intflags,
228+
constchar**hintmsg);
229+
externboolparse_real(constchar*value,double*result);
227230
externboolset_config_option(constchar*name,constchar*value,
228231
GucContextcontext,GucSourcesource,
229232
GucActionaction,boolchangeVal);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp