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

Commite376422

Browse files
committed
pg_dump: Fix incorrect parsing of object types in pg_dump --filter.
Previously, pg_dump --filter could misinterpret invalid object typesin the filter file as valid ones. For example, the invalid object type"table-data" (likely a typo for the valid "table_data") could bemistakenly recognized as "table", causing pg_dump to succeedwhen it should have failed.This happened because pg_dump identified keywords as sequences ofASCII alphabetic characters, treating non-alphabetic characters(like hyphens) as keyword boundaries. As a result, "table-data" wasparsed as "table".To fix this, pg_dump --filter now treats keywords as strings ofnon-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.comBackpatch-through: 17
1 parentce88170 commite376422

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
staticconstchar*
@@ -182,18 +181,22 @@ filter_get_keyword(const char **line, int *size)
182181
constchar*ptr=*line;
183182
constchar*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((unsignedchar)*ptr))
190192
ptr++;
191193

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

196-
while (isalpha((unsignedchar)*ptr)||*ptr=='_')
199+
while (*ptr!='\0'&& !isspace((unsignedchar)*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
ordie"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)

[8]ページ先頭

©2009-2025 Movatter.jp