Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6444f74

Browse files
authored
Merge branch 'postgres:master' into master
2 parents a982386 + 62a47ae commit 6444f74

File tree

19 files changed

+440
-108
lines changed

19 files changed

+440
-108
lines changed

doc/src/sgml/config.sgml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2788,7 +2788,7 @@ include_dir 'conf.d'
27882788
</varlistentry>
27892789

27902790
<varlistentry id="guc-io-workers" xreflabel="io_workers">
2791-
<term><varname>io_workers</varname> (<type>int</type>)
2791+
<term><varname>io_workers</varname> (<type>integer</type>)
27922792
<indexterm>
27932793
<primary><varname>io_workers</varname> configuration parameter</primary>
27942794
</indexterm>
@@ -8602,7 +8602,8 @@ COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv;
86028602
timing information is displayed in
86038603
<link linkend="vacuum-progress-reporting"><structname>pg_stat_progress_vacuum</structname></link>,
86048604
<link linkend="analyze-progress-reporting"><structname>pg_stat_progress_analyze</structname></link>,
8605-
in the output of <xref linkend="sql-vacuum"/> when the
8605+
in the output of <xref linkend="sql-vacuum"/> and
8606+
<xref linkend="sql-analyze"/> when the
86068607
<literal>VERBOSE</literal> option is used, and by autovacuum for
86078608
auto-vacuums and auto-analyzes when
86088609
<xref linkend="guc-log-autovacuum-min-duration"/> is set.
@@ -9340,7 +9341,8 @@ COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv;
93409341
<varlistentry id="guc-vacuum-truncate" xreflabel="vacuum_truncate">
93419342
<term><varname>vacuum_truncate</varname> (<type>boolean</type>)
93429343
<indexterm>
9343-
<primary><varname>vacuum_truncate</varname> configuration parameter</primary>
9344+
<primary><varname>vacuum_truncate</varname></primary>
9345+
<secondary>configuration parameter</secondary>
93449346
</indexterm>
93459347
</term>
93469348
<listitem>
@@ -9544,7 +9546,8 @@ COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv;
95449546
<varlistentry id="guc-vacuum-max-eager-freeze-failure-rate" xreflabel="vacuum_max_eager_freeze_failure_rate">
95459547
<term><varname>vacuum_max_eager_freeze_failure_rate</varname> (<type>floating point</type>)
95469548
<indexterm>
9547-
<primary><varname>vacuum_max_eager_freeze_failure_rate</varname> configuration parameter</primary>
9549+
<primary><varname>vacuum_max_eager_freeze_failure_rate</varname></primary>
9550+
<secondary>configuration parameter</secondary>
95489551
</indexterm>
95499552
</term>
95509553
<listitem>

doc/src/sgml/ddl.sgml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,16 @@ CREATE TABLE people (
419419
<varname>tableoid</varname>.
420420
</para>
421421
</listitem>
422+
<listitem>
423+
<para>
424+
A virtual generated column cannot have a user-defined type, and the
425+
generation expression of a virtual generated column must not reference
426+
user-defined functions or types, that is, it can only use built-in
427+
functions or types. This applies also indirectly, such as for functions
428+
or types that underlie operators or casts. (This restriction does not
429+
exist for stored generated columns.)
430+
</para>
431+
</listitem>
422432
<listitem>
423433
<para>
424434
A generated column cannot have a column default or an identity definition.

doc/src/sgml/protocol.sgml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7292,8 +7292,8 @@ psql "dbname=postgres replication=database" -c "IDENTIFY_SYSTEM;"
72927292
<term>Int64 (XLogRecPtr)</term>
72937293
<listitem>
72947294
<para>
7295-
The LSN of the abort. This field is available since protocol version
7296-
4.
7295+
The LSN of the abort operation, present only when streaming is set to parallel.
7296+
This field is available since protocol version 4.
72977297
</para>
72987298
</listitem>
72997299
</varlistentry>
@@ -7302,9 +7302,9 @@ psql "dbname=postgres replication=database" -c "IDENTIFY_SYSTEM;"
73027302
<term>Int64 (TimestampTz)</term>
73037303
<listitem>
73047304
<para>
7305-
Abort timestamp of the transaction. The value is in number
7306-
of microseconds since PostgreSQL epoch (2000-01-01). This field is
7307-
available since protocol version 4.
7305+
Abort timestamp of the transaction, present only when streaming is set to
7306+
parallel. The value is in number of microseconds since PostgreSQL epoch (2000-01-01).
7307+
This field is available since protocol version 4.
73087308
</para>
73097309
</listitem>
73107310
</varlistentry>

doc/src/sgml/ref/alter_table.sgml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -460,16 +460,16 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
460460
<para>
461461
This form adds a new constraint to a table using the same constraint
462462
syntax as <link linkend="sql-createtable"><command>CREATE TABLE</command></link>, plus the option <literal>NOT
463-
VALID</literal>, which is currently only allowed for foreign key,
464-
<literal>CHECK</literal> constraints and not-null constraints.
463+
VALID</literal>, which is currently only allowed for foreign-key,
464+
<literal>CHECK</literal>, and not-null constraints.
465465
</para>
466466

467467
<para>
468468
Normally, this form will cause a scan of the table to verify that all
469469
existing rows in the table satisfy the new constraint. But if
470470
the <literal>NOT VALID</literal> option is used, this
471471
potentially-lengthy scan is skipped. The constraint will still be
472-
enforced against subsequent inserts or updates (that is, they'll fail
472+
applied against subsequent inserts or updates (that is, they'll fail
473473
unless there is a matching row in the referenced table, in the case
474474
of foreign keys, or they'll fail unless the new row matches the
475475
specified check condition). But the
@@ -591,7 +591,7 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
591591
This form validates a foreign key, check, or not-null constraint that was
592592
previously created as <literal>NOT VALID</literal>, by scanning the
593593
table to ensure there are no rows for which the constraint is not
594-
satisfied. If the constraint is not enforced, an error is thrown.
594+
satisfied. If the constraint was set to <literal>NOT ENFORCED</literal>, an error is thrown.
595595
Nothing happens if the constraint is already marked valid.
596596
(See <xref linkend="sql-altertable-notes"/> below for an explanation
597597
of the usefulness of this command.)
@@ -1466,11 +1466,11 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
14661466
</para>
14671467

14681468
<para>
1469-
Adding an enforced <literal>CHECK</literal> or <literal>NOT NULL</literal>
1469+
Adding a <literal>CHECK</literal> or <literal>NOT NULL</literal>
14701470
constraint requires scanning the table to verify that existing rows meet the
14711471
constraint, but does not require a table rewrite. If a <literal>CHECK</literal>
1472-
constraint is added as <literal>NOT ENFORCED</literal>, the validation will
1473-
not be performed.
1472+
constraint is added as <literal>NOT ENFORCED</literal>, no verification will
1473+
be performed.
14741474
</para>
14751475

14761476
<para>
@@ -1485,7 +1485,7 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
14851485
</para>
14861486

14871487
<para>
1488-
Scanning a large table to verify a new foreign key or check constraint
1488+
Scanning a large table to verify new foreign-key, check, or not-null constraints
14891489
can take a long time, and other updates to the table are locked out
14901490
until the <command>ALTER TABLE ADD CONSTRAINT</command> command is
14911491
committed. The main purpose of the <literal>NOT VALID</literal>

doc/src/sgml/ref/create_table.sgml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,15 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
924924
not other generated columns. Any functions and operators used must be
925925
immutable. References to other tables are not allowed.
926926
</para>
927+
928+
<para>
929+
A virtual generated column cannot have a user-defined type, and the
930+
generation expression of a virtual generated column must not reference
931+
user-defined functions or types, that is, it can only use built-in
932+
functions or types. This applies also indirectly, such as for functions
933+
or types that underlie operators or casts. (This restriction does not
934+
exist for stored generated columns.)
935+
</para>
927936
</listitem>
928937
</varlistentry>
929938

@@ -1694,7 +1703,8 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
16941703
<varlistentry id="reloption-vacuum-truncate" xreflabel="vacuum_truncate">
16951704
<term><literal>vacuum_truncate</literal>, <literal>toast.vacuum_truncate</literal> (<type>boolean</type>)
16961705
<indexterm>
1697-
<primary><varname>vacuum_truncate</varname> storage parameter</primary>
1706+
<primary><varname>vacuum_truncate</varname></primary>
1707+
<secondary>storage parameter</secondary>
16981708
</indexterm>
16991709
</term>
17001710
<listitem>

doc/src/sgml/ref/pg_createsubscriber.sgml

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -169,36 +169,6 @@ PostgreSQL documentation
169169
</listitem>
170170
</varlistentry>
171171

172-
<varlistentry>
173-
<term><option>-R <replaceable class="parameter">objtype</replaceable></option></term>
174-
<term><option>--remove=<replaceable class="parameter">objtype</replaceable></option></term>
175-
<listitem>
176-
<para>
177-
Remove all objects of the specified type from specified databases on the
178-
target server.
179-
</para>
180-
<para>
181-
<itemizedlist>
182-
<listitem>
183-
<para>
184-
<literal>publications</literal>:
185-
The <literal>FOR ALL TABLES</literal> publications established for this
186-
subscriber are always removed; specifying this object type causes all
187-
other publications replicated from the source server to be dropped as
188-
well.
189-
</para>
190-
</listitem>
191-
</itemizedlist>
192-
</para>
193-
<para>
194-
The objects selected to be dropped are individually logged, including during
195-
a <option>--dry-run</option>. There is no opportunity to affect or stop the
196-
dropping of the selected objects, so consider taking a backup of them
197-
using <application>pg_dump</application>.
198-
</para>
199-
</listitem>
200-
</varlistentry>
201-
202172
<varlistentry>
203173
<term><option>-s <replaceable class="parameter">dir</replaceable></option></term>
204174
<term><option>--socketdir=<replaceable class="parameter">dir</replaceable></option></term>
@@ -259,6 +229,35 @@ PostgreSQL documentation
259229
</listitem>
260230
</varlistentry>
261231

232+
<varlistentry>
233+
<term><option>--clean=<replaceable class="parameter">objtype</replaceable></option></term>
234+
<listitem>
235+
<para>
236+
Drop all objects of the specified type from specified databases on the
237+
target server.
238+
</para>
239+
<para>
240+
<itemizedlist>
241+
<listitem>
242+
<para>
243+
<literal>publications</literal>:
244+
The <literal>FOR ALL TABLES</literal> publications established for this
245+
subscriber are always dropped; specifying this object type causes all
246+
other publications replicated from the source server to be dropped as
247+
well.
248+
</para>
249+
</listitem>
250+
</itemizedlist>
251+
</para>
252+
<para>
253+
The objects selected to be dropped are individually logged, including during
254+
a <option>--dry-run</option>. There is no opportunity to affect or stop the
255+
dropping of the selected objects, so consider taking a backup of them
256+
using <application>pg_dump</application>.
257+
</para>
258+
</listitem>
259+
</varlistentry>
260+
262261
<varlistentry>
263262
<term><option>--config-file=<replaceable class="parameter">filename</replaceable></option></term>
264263
<listitem>

src/backend/catalog/heap.c

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,15 @@ CheckAttributeType(const char *attname,
664664
flags);
665665
}
666666

667+
/*
668+
* For consistency with check_virtual_generated_security().
669+
*/
670+
if ((flags & CHKATYPE_IS_VIRTUAL) && atttypid >= FirstUnpinnedObjectId)
671+
ereport(ERROR,
672+
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
673+
errmsg("virtual generated column \"%s\" cannot have a user-defined type", attname),
674+
errdetail("Virtual generated columns that make use of user-defined types are not yet supported."));
675+
667676
/*
668677
* This might not be strictly invalid per SQL standard, but it is pretty
669678
* useless, and it cannot be dumped, so we must disallow it.
@@ -3215,6 +3224,86 @@ check_nested_generated(ParseState *pstate, Node *node)
32153224
check_nested_generated_walker(node, pstate);
32163225
}
32173226

3227+
/*
3228+
* Check security of virtual generated column expression.
3229+
*
3230+
* Just like selecting from a view is exploitable (CVE-2024-7348), selecting
3231+
* from a table with virtual generated columns is exploitable. Users who are
3232+
* concerned about this can avoid selecting from views, but telling them to
3233+
* avoid selecting from tables is less practical.
3234+
*
3235+
* To address this, this restricts generation expressions for virtual
3236+
* generated columns are restricted to using built-in functions and types. We
3237+
* assume that built-in functions and types cannot be exploited for this
3238+
* purpose. Note the overall security also requires that all functions in use
3239+
* a immutable. (For example, there are some built-in non-immutable functions
3240+
* that can run arbitrary SQL.) The immutability is checked elsewhere, since
3241+
* that is a property that needs to hold independent of security
3242+
* considerations.
3243+
*
3244+
* In the future, this could be expanded by some new mechanism to declare
3245+
* other functions and types as safe or trusted for this purpose, but that is
3246+
* to be designed.
3247+
*/
3248+
3249+
/*
3250+
* Callback for check_functions_in_node() that determines whether a function
3251+
* is user-defined.
3252+
*/
3253+
static bool
3254+
contains_user_functions_checker(Oid func_id, void *context)
3255+
{
3256+
return (func_id >= FirstUnpinnedObjectId);
3257+
}
3258+
3259+
/*
3260+
* Checks for all the things we don't want in the generation expressions of
3261+
* virtual generated columns for security reasons. Errors out if it finds
3262+
* one.
3263+
*/
3264+
static bool
3265+
check_virtual_generated_security_walker(Node *node, void *context)
3266+
{
3267+
ParseState *pstate = context;
3268+
3269+
if (node == NULL)
3270+
return false;
3271+
3272+
if (!IsA(node, List))
3273+
{
3274+
if (check_functions_in_node(node, contains_user_functions_checker, NULL))
3275+
ereport(ERROR,
3276+
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3277+
errmsg("generation expression uses user-defined function"),
3278+
errdetail("Virtual generated columns that make use of user-defined functions are not yet supported."),
3279+
parser_errposition(pstate, exprLocation(node)));
3280+
3281+
/*
3282+
* check_functions_in_node() doesn't check some node types (see
3283+
* comment there). We handle CoerceToDomain and MinMaxExpr by
3284+
* checking for built-in types. The other listed node types cannot
3285+
* call user-definable SQL-visible functions.
3286+
*
3287+
* We furthermore need this type check to handle built-in, immutable
3288+
* polymorphic functions such as array_eq().
3289+
*/
3290+
if (exprType(node) >= FirstUnpinnedObjectId)
3291+
ereport(ERROR,
3292+
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3293+
errmsg("generation expression uses user-defined type"),
3294+
errdetail("Virtual generated columns that make use of user-defined types are not yet supported."),
3295+
parser_errposition(pstate, exprLocation(node)));
3296+
}
3297+
3298+
return expression_tree_walker(node, check_virtual_generated_security_walker, context);
3299+
}
3300+
3301+
static void
3302+
check_virtual_generated_security(ParseState *pstate, Node *node)
3303+
{
3304+
check_virtual_generated_security_walker(node, pstate);
3305+
}
3306+
32183307
/*
32193308
* Take a raw default and convert it to a cooked format ready for
32203309
* storage.
@@ -3254,6 +3343,10 @@ cookDefault(ParseState *pstate,
32543343
ereport(ERROR,
32553344
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
32563345
errmsg("generation expression is not immutable")));
3346+
3347+
/* Check security of expressions for virtual generated column */
3348+
if (attgenerated == ATTRIBUTE_GENERATED_VIRTUAL)
3349+
check_virtual_generated_security(pstate, expr);
32573350
}
32583351
else
32593352
{

0 commit comments

Comments
 (0)