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 1txmWk-00EavT-3P for pgsql-hackers@arkaria.postgresql.org; Thu, 27 Mar 2025 12:40:06 +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 1txmWi-005df8-P7 for pgsql-hackers@arkaria.postgresql.org; Thu, 27 Mar 2025 12:40:04 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1txmWi-005ddT-E6 for pgsql-hackers@lists.postgresql.org; Thu, 27 Mar 2025 12:40:04 +0000 Received: from mail-qk1-x72e.google.com ([2607:f8b0:4864:20::72e]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1txmWf-001VuV-2r for pgsql-hackers@lists.postgresql.org; Thu, 27 Mar 2025 12:40:03 +0000 Received: by mail-qk1-x72e.google.com with SMTP id af79cd13be357-7c59e7039eeso149799585a.2 for ; Thu, 27 Mar 2025 05:40:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dunslane-net.20230601.gappssmtp.com; s=20230601; t=1743079200; x=1743684000; darn=lists.postgresql.org; h=content-transfer-encoding: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=UxrRZYfO+PgcVFNV6SNHO8jS7gJoFjzTYJMCqyLc1u8=; b=JkZ9DrJeaqxIIa+XtZEm3XCg1znMbHjjXPJHzkSOn/WRgoCJq8PalZ7ABPxkuXEguG jJpAtESTE0tBhmt1LWlIVQZhDfIu/7y1U/AFB/WDP5awUw6Ccv9Nd8Aa6EpjT7M41k33 8qRiM9AGs1DZmpfazqj+PNcI3q1Bl2z+OkvnM2GQ0Zv9DYP+8ex1W83KkqwiQKoF8F2A 0bNSjR1H+h+13A6/YiCcFuswvHpxgmgJ8yfNv4vFtM0WHn93WddnjJge673UJ+WJ8ZjO ogcjkSkEvywAOd1ed/0DkxeLz/8VFcbFTuYlJodu+TiiteAjPgITcwDaBjULu+/sUBtf 95Ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743079200; x=1743684000; h=content-transfer-encoding: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=UxrRZYfO+PgcVFNV6SNHO8jS7gJoFjzTYJMCqyLc1u8=; b=ejNuzIOnzxWxwls+uIP8d8V/FKG2nL06x6Lb4yezsqt//IX+LWV4SjsRR+d2zaEXCi ajfL+mWW9WS7Mk7+dIlKd0H/OtDnHPVgzZF4DMJ2YKV36Bljw01NKxKOXJfE5Y8Z+zp9 xKNkBpmSGDixI0MWMTkd2jDmNvIM0JDwR/rVbxZnCOddFwwm4QMUZb8LpEV31aNbIZ/W EYHI4WCMAsAt0cWDU/+LptbRl6jIiRN2ZIKuEEl+sn0zgCxakNTaaCLzt4Dq2ldBULmp YHeBA674vAAjZ0thYWWqOo7NaGmh2x474echUxSSvef/Z1UPmn69uOCWBDDqkL8UzWtK YcWQ== X-Forwarded-Encrypted: i=1; AJvYcCV4h10P/VqO6REEqO0mFWmwGPKkwlNTMZbWbH31eubYWaDoh1gPAwlsSWBX2Ea/MG12rOR4LpMGEQDplv0k@lists.postgresql.org X-Gm-Message-State: AOJu0YzqhGVCz7uEz/9RmGqloxZ4XJN1gVXvuUlOZgkbCjtTo95xuYRL zzxO77JfQoygAPY9OWV12laXJVWb358+mTNAmsjFPeBaI9g1qbgXSdwWFwDH4tY= X-Gm-Gg: ASbGnctoZ4/trxYp1W1FYpIvQ2m5b0ewPg+X6Osv4VIkj4oJeuDTsNU++UG6j3xK9Gm clpedDjxSM4ZUePiwfJWioQG7M6XON0JjStzSAH0vt901RaEK98+928mWJFaVcqyPvy0CMHVkFI Jjn858CJJlytNR/O1kUJn4zpHwHf/a9K8GwsjSYaFEeyyKW3bfZy3oKFaTbTPWrcxaoJWlgB3da iAb1+cQMYuVYEtkSxBxqn5yE7ENZdkyZAXsAsT1V+9Z8WjxgSX77iX6AobNVkN1orPDWUXjUk3a APe8rJKSmsxqUz4OG1W+ty29pyj4YwtAj8OLk46XVY7MYsqugjI1N1U= X-Google-Smtp-Source: AGHT+IGc1lJB4uro/dxP22saP03Z9uLFuxJm8tB4/PnmOtPI1aWLXRJMK01rV8qKpkiTgayJzh/wLw== X-Received: by 2002:a05:6214:f08:b0:6e8:8d76:f38c with SMTP id 6a1803df08f44-6ed23917e92mr38017816d6.40.1743079199891; Thu, 27 Mar 2025 05:39:59 -0700 (PDT) Received: from ?IPV6:2605:a601:a681:6b00::1cb? ([2605:a601:a681:6b00::1cb]) by smtp.googlemail.com with ESMTPSA id 6a1803df08f44-6eb3ef1f8dasm79173786d6.39.2025.03.27.05.39.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 27 Mar 2025 05:39:59 -0700 (PDT) Message-ID: Date: Thu, 27 Mar 2025 08:39:57 -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: Mahendra Singh Thalor Cc: Srinath Reddy , pgsql-hackers@lists.postgresql.org References: From: Andrew Dunstan Content-Language: en-US Autocrypt: addr=andrew@dunslane.net; keydata= xsBNBE7KWFkBCAClridxur2AIc7eW2AR7izbfp3EnNefie2HbLF0izW5Ik5UjX2HBXBx4syI gY6b0ugohXrr274+baoAlvSbq6cAoQuEVrk5IZFzt20b1Xkx65FwGSEj526yiKLocqkJceSq Xr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dXOFRkagGmC/viwBDqq5b 5tk76kKmUbZxABEBAAHCwHwEGAEIACYCGwwWIQTkPlhGHfx8v0RpFaWZ+n/LWfw7gQUCZFlx 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: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2025-03-27 Th 7:57 AM, Mahendra Singh Thalor wrote: > On Thu, 27 Mar 2025 at 16:16, Andrew Dunstan wrote: >> >> 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 >> > Thanks Andrew and Srinath for feedback. > > Yes, we should use the strpbrk function. Fixed. > > Here, I am attaching an updated patch which has check in createdb and > RenameDatabase. For older versions, we can add more useful error > message (like: rename database as database has \n\r") > > I will add some TAP tests and will make patches for older branches. > I don't think we can backpatch this. It's a behaviour change. cheers andrew -- Andrew Dunstan EDB: https://www.enterprisedb.com