Skip to content

Commit 7dafc4a

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 9048a83 commit 7dafc4a

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
@@ -172,9 +172,8 @@ pg_log_filter_error(FilterStateData *fstate, const char *fmt,...)
172172
/*
173173
* filter_get_keyword - read the next filter keyword from buffer
174174
*
175-
* Search for keywords (limited to ascii alphabetic characters) in
176-
* the passed in line buffer. Returns NULL when the buffer is empty or the first
177-
* char is not alpha. The char '_' is allowed, except as the first character.
175+
* Search for keywords (strings of non-whitespace characters) in the passed
176+
* in line buffer. Returns NULL when the buffer is empty or no keyword exists.
178177
* The length of the found keyword is returned in the size parameter.
179178
*/
180179
static const char *
@@ -183,18 +182,22 @@ filter_get_keyword(const char **line, int *size)
183182
const char *ptr = *line;
184183
const char *result = NULL;
185184

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

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

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

197-
while (isalpha((unsigned char) *ptr) || *ptr == '_')
200+
while (*ptr != '\0' && !isspace((unsigned char) *ptr))
198201
ptr++;
199202

200203
*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
@@ -374,19 +374,25 @@
374374
qr/invalid filter command/,
375375
"invalid syntax: incorrect filter command");
376376

377-
# Test invalid object type
377+
# Test invalid object type.
378+
#
379+
# This test also verifies that keywords are correctly recognized as strings of
380+
# non-whitespace characters. If the parser incorrectly treats non-whitespace
381+
# delimiters (like hyphens) as keyword boundaries, "table-data" might be
382+
# misread as the valid object type "table". To catch such issues,
383+
# "table-data" is used here as an intentionally invalid object type.
378384
open $inputfile, '>', "$tempdir/inputfile.txt"
379385
or die "unable to open filterfile for writing";
380-
print $inputfile "include xxx";
386+
print $inputfile "exclude table-data one";
381387
close $inputfile;
382388

383389
command_fails_like(
384390
[
385391
'pg_dump', '-p', $port, '-f', $plainfile,
386392
"--filter=$tempdir/inputfile.txt", 'postgres'
387393
],
388-
qr/unsupported filter object type: "xxx"/,
389-
"invalid syntax: invalid object type specified, should be table, schema, foreign_data or data"
394+
qr/unsupported filter object type: "table-data"/,
395+
"invalid syntax: invalid object type specified"
390396
);
391397

392398
# 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