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 1tieRa-000mp9-Rf for pgsql-hackers@arkaria.postgresql.org; Thu, 13 Feb 2025 19:00:14 +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 1tieRY-00CgEe-EF for pgsql-hackers@arkaria.postgresql.org; Thu, 13 Feb 2025 19:00:13 +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 1tieRY-00CgEW-1A for pgsql-hackers@lists.postgresql.org; Thu, 13 Feb 2025 19:00:12 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tieRW-000dDv-2G for pgsql-hackers@lists.postgresql.org; Thu, 13 Feb 2025 19:00:11 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 51DJ095H3718361; Thu, 13 Feb 2025 14:00:10 -0500 From: Tom Lane To: Justin Pryzby cc: pgsql-hackers@lists.postgresql.org Subject: Re: pg17.3 PQescapeIdentifier() ignores len In-reply-to: References: Comments: In-reply-to Justin Pryzby message dated "Thu, 13 Feb 2025 10:51:27 -0600" MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <3718284.1739473173.0@sss.pgh.pa.us> Date: Thu, 13 Feb 2025 14:00:09 -0500 Message-ID: <3718360.1739473209@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3718284.1739473173.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Justin Pryzby writes: > The fprintf suggests that since 5dc1e42b4 PQescapeIdentifier ignores its= len. Ugh, yes. Need something like the attached. FTR, 5dc1e42b4 et al were quite subtle patches done under extreme time pressure. I wonder if they have any other issues. More eyes on those patches would be welcome, now that they are public. regards, tom lane ------- =_aaaaaaaaaa0 Content-Type: text/x-diff; name="fix-PQescapeInternal-ignores-len-parameter.patch"; charset="us-ascii" Content-ID: <3718284.1739473173.2@sss.pgh.pa.us> Content-Description: fix-PQescapeInternal-ignores-len-parameter.patch Content-Transfer-Encoding: quoted-printable diff --git a/src/interfaces/libpq/fe-exec.c b/src/interfaces/libpq/fe-exec= .c index e97ad02542..120d4d032e 100644 --- a/src/interfaces/libpq/fe-exec.c +++ b/src/interfaces/libpq/fe-exec.c @@ -4224,7 +4224,7 @@ PQescapeInternal(PGconn *conn, const char *str, size= _t len, bool as_ident) char *rp; int num_quotes =3D 0; /* single or double, depending on as_ident */ int num_backslashes =3D 0; - size_t input_len =3D strlen(str); + size_t input_len =3D strnlen(str, len); size_t result_size; char quote_char =3D as_ident ? '"' : '\''; bool validated_mb =3D false; @@ -4274,7 +4274,7 @@ PQescapeInternal(PGconn *conn, const char *str, size= _t len, bool as_ident) if (!validated_mb) { if (pg_encoding_verifymbstr(conn->client_encoding, s, remaining) - !=3D strlen(s)) + !=3D remaining) { libpq_append_conn_error(conn, "invalid multibyte character"); return NULL; ------- =_aaaaaaaaaa0--