public inbox for [email protected]  
help / color / mirror / Atom feed
From: Andrew Dunstan <[email protected]>
To: Srinath Reddy <[email protected]>
To: Mahendra Singh Thalor <[email protected]>
Cc: [email protected]
Subject: Re: getting "shell command argument contains a newline or carriage return:" error with pg_dumpall when db name have new line in double quote
Date: Thu, 27 Mar 2025 06:46:50 -0400
Message-ID: <[email protected]> (raw)
In-Reply-To: <CAFC+b6rL3a=5tFGdcVuyHBPEpw_Zdv4HP+NGZvQZBCj07MU5Pg@mail.gmail.com>
References: <CAKYtNApkOi4FY0S7+3jpTqnHVyyZ6Tbzhtbah-NBbY-mGsiKAQ@mail.gmail.com>
	<CAFC+b6qwc+wpt7_b2R6YhpDkrXeFvFd5NoLbTMMoxX9tfOHjpg@mail.gmail.com>
	<CAKYtNAreuQv04Mfy-u=TnOGrp2ofagRPV43XjjnbJb_5JDqC+Q@mail.gmail.com>
	<CAKYtNArY3-HQ53sCDynnhGqjr9DBi07nKjbj00U0tnsZJBnyoQ@mail.gmail.com>
	<CAFC+b6oiZ9b80jgZnYgWuxeOSkSGRhkb-Opjn59kR171sHE=XA@mail.gmail.com>
	<[email protected]>
	<CAFC+b6ocP-8VtvvgVU8npVPp4cc379DvDkRjdRKUc+fa2fKwwg@mail.gmail.com>
	<CAFC+b6rL3a=5tFGdcVuyHBPEpw_Zdv4HP+NGZvQZBCj07MU5Pg@mail.gmail.com>


On 2025-03-26 We 8:52 AM, Srinath Reddy wrote:
> sorry for the noise ,previous response had my editor's formatting,just 
> resending without that formatting.
>
> ./psql postgres
>
> Hi,
>
> On Wed, Mar 26, 2025 at 5:55 PM Andrew Dunstan <[email protected]> 
> wrote:
>
>     You can still create a database with these using "CREATE DATABASE"
>     though. Shouldn't we should really be preventing that?
>
>
> yes, solution 1 which I mentioned prevents these while we are 
> using "CREATE DATABASE".
>
> /*
>   * Create a new database using the WAL_LOG strategy.
> @@ -741,6 +742,13 @@ createdb(ParseState *pstate, const CreatedbStmt 
> *stmt)
>   CreateDBStrategy dbstrategy = CREATEDB_WAL_LOG;
>   createdb_failure_params fparms;
>
> + /* Report error if dbname have newline or carriage return in name. */
> + if (is_name_contain_lfcr(dbname))
> + ereport(ERROR,
> + (errcode(ERRCODE_INVALID_PARAMETER_VALUE)),
> + errmsg("database name contains a newline or carriage return character"),
> + errhint("newline or carriage return character is not allowed in 
> database name"));
> +
>
> psql (18devel)
> Type "help" for help.
>
> postgres=# create database "test
> postgres"# lines";
> ERROR:  database name contains a newline or carriage return character
> HINT:  newline or carriage return character is not allowed in database 
> name
>
>


Yes, sorry, I misread the thread. I think we should proceed with options 
1 and 3 i.e. prevent creation of new databases with a CR or LF, and have 
pgdumpall exit with a more useful error message.

Your invention of an is_name_contain_lfcr() function is unnecessary - we 
can just use the standard library function strpbrk() to look for a CR or LF.


cheers


andrew


--
Andrew Dunstan
EDB:https://www.enterprisedb.com


view thread (29+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected], [email protected]
  Subject: Re: getting "shell command argument contains a newline or carriage return:" error with pg_dumpall when db name have new line in double quote
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox