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.96) (envelope-from ) id 1wgkTH-006N7j-0m for pgsql-hackers@arkaria.postgresql.org; Mon, 06 Jul 2026 14:38:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wgkTG-001Alz-02 for pgsql-hackers@arkaria.postgresql.org; Mon, 06 Jul 2026 14:38:54 +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.96) (envelope-from ) id 1wgkTF-001Alq-2K for pgsql-hackers@lists.postgresql.org; Mon, 06 Jul 2026 14:38:53 +0000 Received: from smtp.outgoing.loopia.se ([93.188.3.37]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wgkTD-00000001rPp-1DjL for pgsql-hackers@postgresql.org; Mon, 06 Jul 2026 14:38:52 +0000 Received: from s807.loopia.se (localhost [127.0.0.1]) by s807.loopia.se (Postfix) with ESMTP id 90CF763C29A for ; Mon, 06 Jul 2026 16:38:48 +0200 (CEST) Received: from s979.loopia.se (unknown [172.22.191.6]) by s807.loopia.se (Postfix) with ESMTP id 7C73663C299; Mon, 06 Jul 2026 16:38:48 +0200 (CEST) Received: from localhost (unknown [172.22.191.6]) by s979.loopia.se (Postfix) with ESMTP id 7B4D210BC35E; Mon, 06 Jul 2026 16:38:48 +0200 (CEST) X-Virus-Scanned: amavis at amavis.loopia.se X-Spam-Flag: NO X-Spam-Score: -1.2 X-Spam-Level: X-Spam-Status: No, score=-1.2 tagged_above=-999 required=6.2 tests=[ALL_TRUSTED=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1] autolearn=disabled Authentication-Results: s898.loopia.se (amavis); dkim=pass (2048-bit key) header.d=yesql.se Received: from s980.loopia.se ([172.22.191.6]) by localhost (s898.loopia.se [172.22.190.17]) (amavis, port 10024) with LMTP id C1XxeIde_3Zu; Mon, 6 Jul 2026 16:38:48 +0200 (CEST) X-Loopia-Auth: user X-Loopia-User: daniel@yesql.se X-Loopia-Originating-IP: 89.255.232.236 Received: from smtpclient.apple (customer-89-255-232-236.stosn.net [89.255.232.236]) (Authenticated sender: daniel@yesql.se) by s980.loopia.se (Postfix) with ESMTPSA id E0F8E2201621; Mon, 06 Jul 2026 16:38:47 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yesql.se; s=loopiadkim1707475645; t=1783348727; bh=CQfNYzcDHGi4ZlSpCCUv3FDb/tx4pIEoNMjiQFmF7rY=; h=Subject:From:In-Reply-To:Date:Cc:References:To; b=RnTUhvzE+ig9NgJh1o5rbQ3pcWX1qmJqOdKCahLCncLwkNT+gxQFAYd8LvogsdzYr dyLRSuI8lCocIQD+J3GVr38y9Bf85RxTrbz7gYhxn1P1yt2AdM0TBKMtKeSH7dNePh AZGPP4csJKTyRwRPltRTGAgWUA2KctGXScib70/I9NAAmz3HrTQrDz3LXm5TiB9JuH mtpbnUOEf48klIHJwTFNUMsqN1bkPmlrkUGUF8q3X5huh5QRCy5zMJ5bRbt/YRmuK4 5mK2pnfUyjPAK8QUA39IcHbsQzuSFJEm2uEfbc76l8DHx/bHVkeWJwZZtNn2z/J6MD eU7qgDY7+vTyQ== Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3776.700.51.11.12\)) Subject: Re: Possible replace of strncpy on xactdesc.c From: Daniel Gustafsson In-Reply-To: Date: Mon, 6 Jul 2026 16:38:37 +0200 Cc: PostgreSQL Hackers Content-Transfer-Encoding: quoted-printable Message-Id: <2F655280-ACEB-47C8-9F0A-35709B96373F@yesql.se> References: To: =?utf-8?Q?Mario_Gonz=C3=A1lez_Troncoso?= X-Mailer: Apple Mail (2.3776.700.51.11.12) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On 3 Jul 2026, at 05:47, Mario Gonz=C3=A1lez Troncoso = wrote: > I've been doing some research about if we could replace strncpy() in > some code. It seems I found one and I'd like your opinion on it to > determine if it's worth the change. >=20 > Basically what I found and IMO it's worth the change is on file = xactdesc.c >=20 > diff --git a/src/backend/access/rmgrdesc/xactdesc.c > b/src/backend/access/rmgrdesc/xactdesc.c > index 4f53d3035cc..0f466a4c27c 100644 > --- a/src/backend/access/rmgrdesc/xactdesc.c > +++ b/src/backend/access/rmgrdesc/xactdesc.c > @@ -256,7 +256,7 @@ ParsePrepareRecord(uint8 info, xl_xact_prepare > *xlrec, xl_xact_parsed_prepare *p > parsed->nabortstats =3D xlrec->nabortstats; > parsed->nmsgs =3D xlrec->ninvalmsgs; >=20 > - strncpy(parsed->twophase_gid, bufptr, xlrec->gidlen); > + strlcpy(parsed->twophase_gid, bufptr, = sizeof(parsed->twophase_gid)); > bufptr +=3D MAXALIGN(xlrec->gidlen); As a general rule it's a good idea to replace strncpy with strlcpy. > The other functions that are inside the file already use strlcpy() so > maybe the use of current strncpy() on xactdesc.c is just code that > comes from the refactor itself. It was introduced in 1eb6d6527aae in twophase.c and then moved to = xaxtdesc.c in the above mentioned commit. > I'll send a proper patch once some feedback is received but at least > it's compiling and passing local tests. Sounds good, please send a patch. -- Daniel Gustafsson