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 1uAb58-00HDA2-EF for pgsql-committers@arkaria.postgresql.org; Thu, 01 May 2025 21:04:34 +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 1uAb56-005Iwj-DQ for pgsql-committers@arkaria.postgresql.org; Thu, 01 May 2025 21:04:33 +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 1uAb56-005Iwb-5v for pgsql-committers@lists.postgresql.org; Thu, 01 May 2025 21:04:33 +0000 Received: from fhigh-b3-smtp.messagingengine.com ([202.12.124.154]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uAb55-000bFN-0P for pgsql-committers@lists.postgresql.org; Thu, 01 May 2025 21:04:32 +0000 Received: from phl-compute-04.internal (phl-compute-04.phl.internal [10.202.2.44]) by mailfhigh.stl.internal (Postfix) with ESMTP id B5CC12540095; Thu, 1 May 2025 17:04:29 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-04.internal (MEProxy); Thu, 01 May 2025 17:04:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eisentraut.org; h=cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1746133469; x=1746219869; bh=HqmvNKfGSzw8ybRIfy6r3QCiayKAVgFcqdaa+WCRRi4=; b= RxO60ZXsVAUXwwy/oy1E3KQJTl0hewkfAAsc8pVie1JZJv6xyuPPQ8RfwUru14xG 4QTFNFtQE/ZR64Ffja5mtHq5+G6EnZAGPyD22KI3saOiahANT3dkNKXdYZolZ8Yj 7ltjYT8bLkI82nNCzNjD79sJJaIGtsfxOTbBk5f4NBLZDZS4gdQbl0KPb8riHwAV RkhmVVBbEDcy1LtMgBhMRGtQKMGSXWZQEypjW7s7IthcexVBGk3bAiPM/m0V6XQ3 cqzCoi9hbpoVmOJEWukQcUqwCFECeGar6pJjyMmtrx3EV7rVkeH7vTVpAm//X4tX zIphcOiJ7RxkLnU69MjBqg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; t=1746133469; x=1746219869; bh=H qmvNKfGSzw8ybRIfy6r3QCiayKAVgFcqdaa+WCRRi4=; b=ixb2BCK4HwO2gyF2y syQoNqcX6oVsdXZgEULhELNf8cfL5MRcCI9XC/AwKhvTTmBMvaCmA29BFo05sVry Mwx2tpsIvp7Z/cCFiE2WUwffxQQ8k9EyjPC3VICjZyUkYaU3UNsdqQSiANl082oU Ag9CHfAZ29GaaWV/pYlJFq+ac8EYr28ZLj3S/SqAuVYpd/a4hkXEjfEutkNjjEgC UlXvM1Ds4Ehgn63uRzagzhhrW2jrp4lS7nn4M+LvCyHSKhZ9+Itpm89B6jV+n5R6 PUsJUZD9F9/wI+Ir7jqiJK0KQxRjDL8tsLDXY1Vz2Zwn3f6b/72gCHfMDu1RW5aN 6LpLw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddvjedtieduucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefkff ggfgfuvfhfhfgjtgfgsehtjeertddtvdejnecuhfhrohhmpefrvghtvghrucfgihhsvghn thhrrghuthcuoehpvghtvghrsegvihhsvghnthhrrghuthdrohhrgheqnecuggftrfgrth htvghrnhepleeuveeuveeiveffledtkeeuffevveffhfejudffvedtheeileejgefgveef veefnecuffhomhgrihhnpehpohhsthhgrhdrvghspdhpohhsthhgrhgvshhqlhdrohhrgh enucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpvght vghrsegvihhsvghnthhrrghuthdrohhrghdpnhgspghrtghpthhtohepvddpmhhouggvpe hsmhhtphhouhhtpdhrtghpthhtohepthhglhesshhsshdrphhghhdrphgrrdhushdprhgt phhtthhopehpghhsqhhlqdgtohhmmhhithhtvghrsheslhhishhtshdrphhoshhtghhrvg hsqhhlrdhorhhg X-ME-Proxy: Feedback-ID: ie0a040ee:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 1 May 2025 17:04:28 -0400 (EDT) Message-ID: Date: Thu, 1 May 2025 23:04:27 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: pgsql: Make escaping functions retain trailing bytes of an invalid char To: Tom Lane , pgsql-committers@lists.postgresql.org References: Content-Language: en-US From: Peter Eisentraut In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 15.02.25 22:20, Tom Lane wrote: > Make escaping functions retain trailing bytes of an invalid character. > > Instead of dropping the trailing byte(s) of an invalid or incomplete > multibyte character, replace only the first byte with a known-invalid > sequence, and process the rest normally. This seems less likely to > confuse incautious callers than the behavior adopted in 5dc1e42b4. > > While we're at it, adjust PQescapeStringInternal to produce at most > one bleat about invalid multibyte characters per string. This > matches the behavior of PQescapeInternal, and avoids the risk of > producing tons of repetitive junk if a long string is simply given > in the wrong encoding. > > This is a followup to the fixes for CVE-2025-1094, and should be > included if cherry-picking those fixes. > > Author: Andres Freund > Co-authored-by: Tom Lane > Reported-by: Jeff Davis > Discussion: https://postgr.es/m/20250215012712.45@rfd.leadboat.com > Backpatch-through: 13 > > Branch > ------ > REL_15_STABLE > > Details > ------- > https://git.postgresql.org/pg/commitdiff/e782a63ccb76a8db476abb8f5d96397806e3e51b > > Modified Files > -------------- > src/fe_utils/string_utils.c | 91 ++++++++++++++++-------------------------- > src/interfaces/libpq/fe-exec.c | 73 +++++++++++++++------------------ > 2 files changed, 67 insertions(+), 97 deletions(-) I think the backpatch of this to PG15 and older has erroneously dropped newlines at the end of some error messages. (libpq in newer PG uses libpq_append_conn_error() etc. and does not have newlines in error message strings anymore.) I think this fix would be appropriate for PG15 and older: diff --git a/src/interfaces/libpq/fe-exec.c b/src/interfaces/libpq/fe-exec.c index 4a4731d048c..73c3a0f9025 100644 --- a/src/interfaces/libpq/fe-exec.c +++ b/src/interfaces/libpq/fe-exec.c @@ -4040,10 +4040,10 @@ PQescapeStringInternal(PGconn *conn, { if (remaining < charlen) appendPQExpBufferStr(&conn->errorMessage, - libpq_gettext("incomplete multibyte character")); + libpq_gettext("incomplete multibyte character\n")); else appendPQExpBufferStr(&conn->errorMessage, - libpq_gettext("invalid multibyte character")); + libpq_gettext("invalid multibyte character\n")); /* Issue a complaint only once per string */ already_complained = true; }