Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1txklJ-00EB0W-Ef for pgsql-hackers@arkaria.postgresql.org; Thu, 27 Mar 2025 10:47:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1txklH-003y4C-Ld for pgsql-hackers@arkaria.postgresql.org; Thu, 27 Mar 2025 10:46:59 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1txklG-003y3M-TT for pgsql-hackers@lists.postgresql.org; Thu, 27 Mar 2025 10:46:59 +0000 Received: from mail-qv1-xf31.google.com ([2607:f8b0:4864:20::f31]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1txklD-001PlB-02 for pgsql-hackers@lists.postgresql.org; Thu, 27 Mar 2025 10:46:56 +0000 Received: by mail-qv1-xf31.google.com with SMTP id 6a1803df08f44-6e8f43c1fa0so8737626d6.3 for ; Thu, 27 Mar 2025 03:46:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dunslane-net.20230601.gappssmtp.com; s=20230601; t=1743072413; x=1743677213; darn=lists.postgresql.org; h=in-reply-to:autocrypt:content-language:from:references:cc:to :subject:user-agent:mime-version:date:message-id:from:to:cc:subject :date:message-id:reply-to; bh=Yfo6EPCcVKpa/rur6HY6aZkopC5yS4hm1CbXo++AYPA=; b=pOyNV8VmFeAmF2Tn6KKvRg6f7vhW8cn2MjIfNyOChBNN+wVVMwNZwF/pZnUn1eP8e4 07bJfrkZONvxhLPUicJmQsPUuxeste+rljY1Cpq6Qn/rjU02G6srngX2I/GhmmyQdF8M N9KEiMWl1nzdeNNwt0rTvbH/SdU5XpXX2hml37vW6jCrE+EacG4zoU/ncIhpZqi7M5a0 38Kc16vxnZAvMshhiUv0CmtmkOZI/paTkOCTNqr52d4dlX40JWIrBNh65a+N/z/h183W QcuAXuzjKJPyYF8bzcFSApIdnBChVE0FPpuR8Hx/QIKGuSa/cpNrmHtVSKaaGnNZZOM+ PXeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743072413; x=1743677213; h=in-reply-to:autocrypt:content-language:from:references:cc:to :subject:user-agent:mime-version:date:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=Yfo6EPCcVKpa/rur6HY6aZkopC5yS4hm1CbXo++AYPA=; b=C8N/iKTIJEqzE/T5pRJTbY2f9x+o8+hDD4RPjLAo0MpuN6fzhnY7hacUffI8fZUONj 4kZ/XG94sKFHH3+sxtaqJ4a5WP48M9oHlaq0MNZM1jmwgRUa4JetU6jwUKLBxW54QTzo LXD/eSTqElGQjckqyVBRsfBlBPNEw0RSVeKVTF+kbot3sRb5aP32Lhpg15+DDLdXIuZF SNRlEgXNIuzxhyI28ofL6+c8Mo4vD+vUBJRboicxfn2eHnuQGpLG2s86REgQsM6lsa9I qa2QWKHUs6/aEg5bvrs/ae+lmDLbq9J/zF9T26RCv7luLr8f3J1WheNF/c/L+xfgp7l2 EIDg== X-Gm-Message-State: AOJu0Yx+1Qe+kKrvfNB8o5+4pX95GoD7Fr1WcVn5awEVpvqxd+SyJoaZ a2jmODsgVrpf14S6wKuBzTTlXQdQ4HvBlfnPVDGCgwprzaPiPFiWQIqk/v4nr6Q= X-Gm-Gg: ASbGncuHBw8NMF+QRGjILly26A1fmlvDuqLRfpTxRZ8rGt8JnQAq8j3uMc2fMj5dKz0 gp3gy4yeBvEbmrwQjdEXCGlA0YkLbQqsAzQ1ajvCDa9f7vahzT4rZ1T1Yr2HMZOgjDbpESf0gEy bx9B7vQ4iOWCpfdzOndyqquqQBwPXgRZQOxDkBpSqyKC81C9VBmxXnSL7eDMIHGvmAIYpvC5aRs FSB0wT6vTDqKQSHQS96HTrFEicvrdm1tXUlJKFAJjUMGYzyERrF1qosXPd+pnEiXWfguOaVWC40 e4AvfZ9EXlYklV96vyUjmkqOC66v46Fpe2CsgmCz3RqaFBiYoMCl/Nw= X-Google-Smtp-Source: AGHT+IF5Rlfpwjv1OlD5g63iuoYKSf3za3HT/2w6kF0t6iaGHWk65GWlM8Olt34K9ImyFw5gpj+yOA== X-Received: by 2002:ad4:5de8:0:b0:6e6:6598:84c1 with SMTP id 6a1803df08f44-6ed239236b7mr39611266d6.42.1743072413251; Thu, 27 Mar 2025 03:46:53 -0700 (PDT) Received: from ?IPV6:2605:a601:a681:6b00::1cb? ([2605:a601:a681:6b00::1cb]) by smtp.googlemail.com with ESMTPSA id 6a1803df08f44-6eb3ef31ae0sm78299916d6.65.2025.03.27.03.46.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 27 Mar 2025 03:46:52 -0700 (PDT) Content-Type: multipart/alternative; boundary="------------jfNgQYR5StM7anJ02g0KN5Go" Message-ID: Date: Thu, 27 Mar 2025 06:46:50 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird 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 To: Srinath Reddy , Mahendra Singh Thalor Cc: pgsql-hackers@lists.postgresql.org References: From: Andrew Dunstan Content-Language: en-US Autocrypt: addr=andrew@dunslane.net; keydata= xsBNBE7KWFkBCAClridxur2AIc7eW2AR7izbfp3EnNefie2HbLF0izW5Ik5UjX2HBXBx4syI gY6b0ugohXrr274+baoAlvSbq6cAoQuEVrk5IZFzt20b1Xkx65FwGSEj526yiKLocqkJceSq Xr9xcA5SGY+FZv441chh5SU92v4q6z+6LPpoHOh97ptAVXZYNTtU0LevyvD5lja0TzbvJm6C eFXitJfnm1pLEr0DGJCR/iU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CZFlx 5wUJGVGAjgAKCRCZ+n/LWfw7gf+iB/4g8CPY5jihf5r/8EsoIGe2H+dpVmpPF8YGBzTIvCz/ fQoOq8AX/pE76QEuFnFZWfjw+wgBXgCVmkox2Eflkk6z4ND3pcwGZ6CfCxTQCDk/dij+2DQ4 6bmDCy/sBgcbz9mTpoLC11HLoPae6YN9nBNQRZDcEFEu54OaVOqlIdbA6m+POIBCXZdHOFc0 WoDTgxHRzC1jgQNidyd6tKqcsVJs0dzF0oKTmFFmUAqTdJO12LBuNA1rlqrR3EtpYk8B/wtS 5dIMD7Q8hwQpL+4C6GNpb6ZKnPkLi47pDOLhz2qBrqN+rqUEsT3YnExYpzj5yOBi+FlmV1Hw 49QYe1sn2ZPs In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------jfNgQYR5StM7anJ02g0KN5Go Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 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 > 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 --------------jfNgQYR5StM7anJ02g0KN5Go Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit


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 <andrew@dunslane.net> 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
--------------jfNgQYR5StM7anJ02g0KN5Go--