Skip to content

Commit 85ccd7e

Browse files
committed
pg_dump: Fix incorrect parsing of object types in pg_dump --filter.
Previously, pg_dump --filter could misinterpret invalid object types in the filter file as valid ones. For example, the invalid object type "table-data" (likely a typo for the valid "table_data") could be mistakenly recognized as "table", causing pg_dump to succeed when it should have failed. This happened because pg_dump identified keywords as sequences of ASCII alphabetic characters, treating non-alphabetic characters (like hyphens) as keyword boundaries. As a result, "table-data" was parsed as "table". To fix this, pg_dump --filter now treats keywords as strings of non-whitespace characters, ensuring invalid types like "table-data" are correctly rejected. Back-patch to v17, where the --filter option was introduced. Author: Fujii Masao <masao.fujii@gmail.com> Reviewed-by: Xuneng Zhou <xunengzhou@gmail.com> Reviewed-by: Srinath Reddy <srinath2133@gmail.com> Reviewed-by: Daniel Gustafsson <daniel@yesql.se> Discussion: https://postgr.es/m/CAHGQGwFzPKUwiV5C-NLBqz1oK1+z9K8cgrF+LcxFem-p3_Ftug@mail.gmail.com Backpatch-through: 17
1 parent 62a1211 commit 85ccd7e

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

src/bin/pg_dump/filter.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,8 @@ pg_log_filter_error(FilterStateData *fstate, const char *fmt,...)
171171
/*
172172
* filter_get_keyword - read the next filter keyword from buffer
173173
*
174-
* Search for keywords (limited to ascii alphabetic characters) in
175-
* the passed in line buffer. Returns NULL when the buffer is empty or the first
176-
* char is not alpha. The char '_' is allowed, except as the first character.
174+
* Search for keywords (strings of non-whitespace characters) in the passed
175+
* in line buffer. Returns NULL when the buffer is empty or no keyword exists.
177176
* The length of the found keyword is returned in the size parameter.
178177
*/
179178
static const char *
@@ -182,18 +181,22 @@ filter_get_keyword(const char **line, int *size)
182181
const char *ptr = *line;
183182
const char *result = NULL;
184183

184+
/* The passed buffer must not be NULL */
185+
Assert(*line != NULL);
186+
185187
/* Set returned length preemptively in case no keyword is found */
186188
*size = 0;
187189

188190
/* Skip initial whitespace */
189191
while (isspace((unsigned char) *ptr))
190192
ptr++;
191193

192-
if (isalpha((unsigned char) *ptr))
194+
/* Grab one keyword that's the string of non-whitespace characters */
195+
if (*ptr != '\0' && !isspace((unsigned char) *ptr))
193196
{
194197
result = ptr++;
195198

196-
while (isalpha((unsigned char) *ptr) || *ptr == '_')
199+
while (*ptr != '\0' && !isspace((unsigned char) *ptr))
197200
ptr++;
198201

199202
*size = ptr - result;

src/bin/pg_dump/t/005_pg_dump_filterfile.pl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -418,10 +418,16 @@
418418
qr/invalid filter command/,
419419
"invalid syntax: incorrect filter command");
420420

421-
# Test invalid object type
421+
# Test invalid object type.
422+
#
423+
# This test also verifies that keywords are correctly recognized as strings of
424+
# non-whitespace characters. If the parser incorrectly treats non-whitespace
425+
# delimiters (like hyphens) as keyword boundaries, "table-data" might be
426+
# misread as the valid object type "table". To catch such issues,
427+
# "table-data" is used here as an intentionally invalid object type.
422428
open $inputfile, '>', "$tempdir/inputfile.txt"
423429
or die "unable to open filterfile for writing";
424-
print $inputfile "include xxx";
430+
print $inputfile "exclude table-data one";
425431
close $inputfile;
426432

427433
command_fails_like(
@@ -432,8 +438,8 @@
432438
'--filter' => "$tempdir/inputfile.txt",
433439
'postgres'
434440
],
435-
qr/unsupported filter object type: "xxx"/,
436-
"invalid syntax: invalid object type specified, should be table, schema, foreign_data or data"
441+
qr/unsupported filter object type: "table-data"/,
442+
"invalid syntax: invalid object type specified"
437443
);
438444

439445
# Test missing object identifier pattern

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