From efdca757b57cbd80518e0d7342c6635fe029d7e4 Mon Sep 17 00:00:00 2001 From: Mahendra Singh Thalor Date: Mon, 24 Mar 2025 22:52:47 +0530 Subject: [PATCH] in dump, report WARNING if dbname have \n\r and skip dump for particular database --- src/bin/pg_dump/pg_dumpall.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index 2935cac2c46..83242261d8d 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -81,6 +81,7 @@ static void executeCommand(PGconn *conn, const char *query); static void expand_dbname_patterns(PGconn *conn, SimpleStringList *patterns, SimpleStringList *names); static void read_dumpall_filters(const char *filename, SimpleStringList *pattern); +static bool is_name_contain_lfcr(char *name); static char pg_dump_bin[MAXPGPATH]; static const char *progname; @@ -1596,6 +1597,13 @@ dumpDatabases(PGconn *conn) if (strcmp(dbname, "template0") == 0) continue; + /* Report warning if database name have \n\r */ + if (is_name_contain_lfcr(dbname)) + { + pg_log_warning("database name has newline or carriage return so skiping dump for this database."); + continue; + } + /* Skip any explicitly excluded database */ if (simple_string_list_member(&database_exclude_names, dbname)) { @@ -2068,3 +2076,22 @@ read_dumpall_filters(const char *filename, SimpleStringList *pattern) filter_free(&fstate); } + +/* + * is_name_contain_lfcr + * + * If dbame has \n or \r in the name, then will return true. + */ +static bool +is_name_contain_lfcr(char *name) +{ + const char *p; + + for (p = name; *p; p++) + { + if (*p == '\n' || *p == '\r') + return true; + } + + return false; +} -- 2.39.3