mirror of
https://github.com/postgres/postgres.git
synced 2025-07-08 11:42:09 +03:00
Introduce variables for initial and max nesting depth on configuration files
The code has been assuming already in a few places that the initial
recursion nesting depth is 0, and the recent changes in hba.c (mainly
783e8c6
) have relies on this assumption in more places. The maximum
recursion nesting level is assumed to be 10 for hba.c and GUCs.
Author: Julien Rouhaud
Discussion: https://postgr.es/m/20221124090724.n7amf5kpdhx6vb76@jrouhaud
This commit is contained in:
@ -60,6 +60,7 @@
|
|||||||
#include "tcop/utility.h"
|
#include "tcop/utility.h"
|
||||||
#include "utils/acl.h"
|
#include "utils/acl.h"
|
||||||
#include "utils/builtins.h"
|
#include "utils/builtins.h"
|
||||||
|
#include "utils/conffiles.h"
|
||||||
#include "utils/fmgroids.h"
|
#include "utils/fmgroids.h"
|
||||||
#include "utils/lsyscache.h"
|
#include "utils/lsyscache.h"
|
||||||
#include "utils/memutils.h"
|
#include "utils/memutils.h"
|
||||||
@ -515,7 +516,8 @@ parse_extension_control_file(ExtensionControlFile *control,
|
|||||||
* Parse the file content, using GUC's file parsing code. We need not
|
* Parse the file content, using GUC's file parsing code. We need not
|
||||||
* check the return value since any errors will be thrown at ERROR level.
|
* check the return value since any errors will be thrown at ERROR level.
|
||||||
*/
|
*/
|
||||||
(void) ParseConfigFp(file, filename, 0, ERROR, &head, &tail);
|
(void) ParseConfigFp(file, filename, CONF_FILE_START_DEPTH, ERROR,
|
||||||
|
&head, &tail);
|
||||||
|
|
||||||
FreeFile(file);
|
FreeFile(file);
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ typedef struct
|
|||||||
/*
|
/*
|
||||||
* Memory context holding the list of TokenizedAuthLines when parsing
|
* Memory context holding the list of TokenizedAuthLines when parsing
|
||||||
* HBA or ident configuration files. This is created when opening the first
|
* HBA or ident configuration files. This is created when opening the first
|
||||||
* file (depth of 0).
|
* file (depth of CONF_FILE_START_DEPTH).
|
||||||
*/
|
*/
|
||||||
static MemoryContext tokenize_context = NULL;
|
static MemoryContext tokenize_context = NULL;
|
||||||
|
|
||||||
@ -620,7 +620,7 @@ free_auth_file(FILE *file, int depth)
|
|||||||
FreeFile(file);
|
FreeFile(file);
|
||||||
|
|
||||||
/* If this is the last cleanup, remove the tokenization context */
|
/* If this is the last cleanup, remove the tokenization context */
|
||||||
if (depth == 0)
|
if (depth == CONF_FILE_START_DEPTH)
|
||||||
{
|
{
|
||||||
MemoryContextDelete(tokenize_context);
|
MemoryContextDelete(tokenize_context);
|
||||||
tokenize_context = NULL;
|
tokenize_context = NULL;
|
||||||
@ -650,7 +650,7 @@ open_auth_file(const char *filename, int elevel, int depth,
|
|||||||
* avoid dumping core due to stack overflow if an include file loops back
|
* avoid dumping core due to stack overflow if an include file loops back
|
||||||
* to itself. The maximum nesting depth is pretty arbitrary.
|
* to itself. The maximum nesting depth is pretty arbitrary.
|
||||||
*/
|
*/
|
||||||
if (depth > 10)
|
if (depth > CONF_FILE_MAX_DEPTH)
|
||||||
{
|
{
|
||||||
ereport(elevel,
|
ereport(elevel,
|
||||||
(errcode_for_file_access(),
|
(errcode_for_file_access(),
|
||||||
@ -684,7 +684,7 @@ open_auth_file(const char *filename, int elevel, int depth,
|
|||||||
* tokenization. This will be closed with this file when coming back to
|
* tokenization. This will be closed with this file when coming back to
|
||||||
* this level of cleanup.
|
* this level of cleanup.
|
||||||
*/
|
*/
|
||||||
if (depth == 0)
|
if (depth == CONF_FILE_START_DEPTH)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* A context may be present, but assume that it has been eliminated
|
* 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,
|
|||||||
|
|
||||||
initStringInfo(&buf);
|
initStringInfo(&buf);
|
||||||
|
|
||||||
if (depth == 0)
|
if (depth == CONF_FILE_START_DEPTH)
|
||||||
*tok_lines = NIL;
|
*tok_lines = NIL;
|
||||||
|
|
||||||
while (!feof(file) && !ferror(file))
|
while (!feof(file) && !ferror(file))
|
||||||
|
@ -202,7 +202,7 @@ ParseConfigFile(const char *config_file, bool strict,
|
|||||||
* avoid dumping core due to stack overflow if an include file loops back
|
* avoid dumping core due to stack overflow if an include file loops back
|
||||||
* to itself. The maximum nesting depth is pretty arbitrary.
|
* to itself. The maximum nesting depth is pretty arbitrary.
|
||||||
*/
|
*/
|
||||||
if (depth > 10)
|
if (depth > CONF_FILE_MAX_DEPTH)
|
||||||
{
|
{
|
||||||
ereport(elevel,
|
ereport(elevel,
|
||||||
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
|
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
|
||||||
@ -321,7 +321,8 @@ GUC_flex_fatal(const char *msg)
|
|||||||
* Input parameters:
|
* Input parameters:
|
||||||
* fp: file pointer from AllocateFile for the configuration file to parse
|
* fp: file pointer from AllocateFile for the configuration file to parse
|
||||||
* config_file: absolute or relative path name of the configuration file
|
* config_file: absolute or relative path name of the configuration file
|
||||||
* depth: recursion depth (should be 0 in the outermost call)
|
* depth: recursion depth (should be CONF_FILE_START_DEPTH in the outermost
|
||||||
|
* call)
|
||||||
* elevel: error logging level to use
|
* elevel: error logging level to use
|
||||||
* Input/Output parameters:
|
* Input/Output parameters:
|
||||||
* head_p, tail_p: head and tail of linked list of name/value pairs
|
* head_p, tail_p: head and tail of linked list of name/value pairs
|
||||||
|
@ -44,6 +44,7 @@
|
|||||||
#include "utils/acl.h"
|
#include "utils/acl.h"
|
||||||
#include "utils/backend_status.h"
|
#include "utils/backend_status.h"
|
||||||
#include "utils/builtins.h"
|
#include "utils/builtins.h"
|
||||||
|
#include "utils/conffiles.h"
|
||||||
#include "utils/float.h"
|
#include "utils/float.h"
|
||||||
#include "utils/guc_tables.h"
|
#include "utils/guc_tables.h"
|
||||||
#include "utils/memutils.h"
|
#include "utils/memutils.h"
|
||||||
@ -287,7 +288,7 @@ ProcessConfigFileInternal(GucContext context, bool applySettings, int elevel)
|
|||||||
head = tail = NULL;
|
head = tail = NULL;
|
||||||
|
|
||||||
if (!ParseConfigFile(ConfigFileName, true,
|
if (!ParseConfigFile(ConfigFileName, true,
|
||||||
NULL, 0, 0, elevel,
|
NULL, 0, CONF_FILE_START_DEPTH, elevel,
|
||||||
&head, &tail))
|
&head, &tail))
|
||||||
{
|
{
|
||||||
/* Syntax error(s) detected in the file, so bail out */
|
/* Syntax error(s) detected in the file, so bail out */
|
||||||
@ -304,7 +305,7 @@ ProcessConfigFileInternal(GucContext context, bool applySettings, int elevel)
|
|||||||
if (DataDir)
|
if (DataDir)
|
||||||
{
|
{
|
||||||
if (!ParseConfigFile(PG_AUTOCONF_FILENAME, false,
|
if (!ParseConfigFile(PG_AUTOCONF_FILENAME, false,
|
||||||
NULL, 0, 0, elevel,
|
NULL, 0, CONF_FILE_START_DEPTH, elevel,
|
||||||
&head, &tail))
|
&head, &tail))
|
||||||
{
|
{
|
||||||
/* Syntax error(s) detected in the file, so bail out */
|
/* Syntax error(s) detected in the file, so bail out */
|
||||||
@ -4582,7 +4583,8 @@ AlterSystemSetConfigFile(AlterSystemStmt *altersysstmt)
|
|||||||
AutoConfFileName)));
|
AutoConfFileName)));
|
||||||
|
|
||||||
/* parse it */
|
/* parse it */
|
||||||
if (!ParseConfigFp(infile, AutoConfFileName, 0, LOG, &head, &tail))
|
if (!ParseConfigFp(infile, AutoConfFileName, CONF_FILE_START_DEPTH,
|
||||||
|
LOG, &head, &tail))
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode(ERRCODE_CONFIG_FILE_ERROR),
|
(errcode(ERRCODE_CONFIG_FILE_ERROR),
|
||||||
errmsg("could not parse contents of file \"%s\"",
|
errmsg("could not parse contents of file \"%s\"",
|
||||||
|
@ -13,6 +13,10 @@
|
|||||||
#ifndef CONFFILES_H
|
#ifndef CONFFILES_H
|
||||||
#define CONFFILES_H
|
#define CONFFILES_H
|
||||||
|
|
||||||
|
/* recursion nesting depth for configuration files */
|
||||||
|
#define CONF_FILE_START_DEPTH 0
|
||||||
|
#define CONF_FILE_MAX_DEPTH 10
|
||||||
|
|
||||||
extern char *AbsoluteConfigLocation(const char *location,
|
extern char *AbsoluteConfigLocation(const char *location,
|
||||||
const char *calling_file);
|
const char *calling_file);
|
||||||
extern char **GetConfFilesInDir(const char *includedir,
|
extern char **GetConfFilesInDir(const char *includedir,
|
||||||
|
Reference in New Issue
Block a user