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

Commitd13b684

Browse files
committed
Introduce variables for initial and max nesting depth on configuration files
The code has been assuming already in a few places that the initialrecursion nesting depth is 0, and the recent changes in hba.c (mainly783e8c6) have relies on this assumption in more places. The maximumrecursion nesting level is assumed to be 10 for hba.c and GUCs.Author: Julien RouhaudDiscussion:https://postgr.es/m/20221124090724.n7amf5kpdhx6vb76@jrouhaud
1 parent2d1f3bc commitd13b684

File tree

5 files changed

+20
-11
lines changed

5 files changed

+20
-11
lines changed

‎src/backend/commands/extension.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
#include"tcop/utility.h"
6161
#include"utils/acl.h"
6262
#include"utils/builtins.h"
63+
#include"utils/conffiles.h"
6364
#include"utils/fmgroids.h"
6465
#include"utils/lsyscache.h"
6566
#include"utils/memutils.h"
@@ -515,7 +516,8 @@ parse_extension_control_file(ExtensionControlFile *control,
515516
* Parse the file content, using GUC's file parsing code. We need not
516517
* check the return value since any errors will be thrown at ERROR level.
517518
*/
518-
(void)ParseConfigFp(file,filename,0,ERROR,&head,&tail);
519+
(void)ParseConfigFp(file,filename,CONF_FILE_START_DEPTH,ERROR,
520+
&head,&tail);
519521

520522
FreeFile(file);
521523

‎src/backend/libpq/hba.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ typedef struct
7979
/*
8080
* Memory context holding the list of TokenizedAuthLines when parsing
8181
* HBA or ident configuration files. This is created when opening the first
82-
* file (depth of0).
82+
* file (depth ofCONF_FILE_START_DEPTH).
8383
*/
8484
staticMemoryContexttokenize_context=NULL;
8585

@@ -620,7 +620,7 @@ free_auth_file(FILE *file, int depth)
620620
FreeFile(file);
621621

622622
/* If this is the last cleanup, remove the tokenization context */
623-
if (depth==0)
623+
if (depth==CONF_FILE_START_DEPTH)
624624
{
625625
MemoryContextDelete(tokenize_context);
626626
tokenize_context=NULL;
@@ -650,7 +650,7 @@ open_auth_file(const char *filename, int elevel, int depth,
650650
* avoid dumping core due to stack overflow if an include file loops back
651651
* to itself. The maximum nesting depth is pretty arbitrary.
652652
*/
653-
if (depth>10)
653+
if (depth>CONF_FILE_MAX_DEPTH)
654654
{
655655
ereport(elevel,
656656
(errcode_for_file_access(),
@@ -684,7 +684,7 @@ open_auth_file(const char *filename, int elevel, int depth,
684684
* tokenization. This will be closed with this file when coming back to
685685
* this level of cleanup.
686686
*/
687-
if (depth==0)
687+
if (depth==CONF_FILE_START_DEPTH)
688688
{
689689
/*
690690
* A context may be present, but assume that it has been eliminated
@@ -762,7 +762,7 @@ tokenize_auth_file(const char *filename, FILE *file, List **tok_lines,
762762

763763
initStringInfo(&buf);
764764

765-
if (depth==0)
765+
if (depth==CONF_FILE_START_DEPTH)
766766
*tok_lines=NIL;
767767

768768
while (!feof(file)&& !ferror(file))

‎src/backend/utils/misc/guc-file.l

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ ParseConfigFile(const char *config_file, bool strict,
202202
* avoid dumping core due to stack overflow if an include file loops back
203203
* to itself. The maximum nesting depth is pretty arbitrary.
204204
*/
205-
if (depth >10)
205+
if (depth >CONF_FILE_MAX_DEPTH)
206206
{
207207
ereport(elevel,
208208
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
@@ -321,7 +321,8 @@ GUC_flex_fatal(const char *msg)
321321
* Input parameters:
322322
*fp: file pointer from AllocateFile for the configuration file to parse
323323
*config_file: absolute or relative path name of the configuration file
324-
*depth: recursion depth (should be 0 in the outermost call)
324+
*depth: recursion depth (should be CONF_FILE_START_DEPTH in the outermost
325+
*call)
325326
*elevel: error logging level to use
326327
* Input/Output parameters:
327328
*head_p, tail_p: head and tail of linked list of name/value pairs

‎src/backend/utils/misc/guc.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include"utils/acl.h"
4545
#include"utils/backend_status.h"
4646
#include"utils/builtins.h"
47+
#include"utils/conffiles.h"
4748
#include"utils/float.h"
4849
#include"utils/guc_tables.h"
4950
#include"utils/memutils.h"
@@ -287,7 +288,7 @@ ProcessConfigFileInternal(GucContext context, bool applySettings, int elevel)
287288
head=tail=NULL;
288289

289290
if (!ParseConfigFile(ConfigFileName, true,
290-
NULL,0,0,elevel,
291+
NULL,0,CONF_FILE_START_DEPTH,elevel,
291292
&head,&tail))
292293
{
293294
/* Syntax error(s) detected in the file, so bail out */
@@ -304,7 +305,7 @@ ProcessConfigFileInternal(GucContext context, bool applySettings, int elevel)
304305
if (DataDir)
305306
{
306307
if (!ParseConfigFile(PG_AUTOCONF_FILENAME, false,
307-
NULL,0,0,elevel,
308+
NULL,0,CONF_FILE_START_DEPTH,elevel,
308309
&head,&tail))
309310
{
310311
/* Syntax error(s) detected in the file, so bail out */
@@ -4582,7 +4583,8 @@ AlterSystemSetConfigFile(AlterSystemStmt *altersysstmt)
45824583
AutoConfFileName)));
45834584

45844585
/* parse it */
4585-
if (!ParseConfigFp(infile,AutoConfFileName,0,LOG,&head,&tail))
4586+
if (!ParseConfigFp(infile,AutoConfFileName,CONF_FILE_START_DEPTH,
4587+
LOG,&head,&tail))
45864588
ereport(ERROR,
45874589
(errcode(ERRCODE_CONFIG_FILE_ERROR),
45884590
errmsg("could not parse contents of file \"%s\"",

‎src/include/utils/conffiles.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
#ifndefCONFFILES_H
1414
#defineCONFFILES_H
1515

16+
/* recursion nesting depth for configuration files */
17+
#defineCONF_FILE_START_DEPTH0
18+
#defineCONF_FILE_MAX_DEPTH10
19+
1620
externchar*AbsoluteConfigLocation(constchar*location,
1721
constchar*calling_file);
1822
externchar**GetConfFilesInDir(constchar*includedir,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp