On Mon, 6 Jul 2026 at 18:26, Mario González Troncoso <[email protected]> wrote: > > On Mon, 6 Jul 2026 at 10:38, Daniel Gustafsson <[email protected]> wrote: > > > > > > 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. > > > > Great. Sending it now after rebasing from master and passing local > tests (long live cirrus CI). > > I added this to the commitfest as well > https://commitfest.postgresql.org/patch/6989/ > > > >
Hopefully with the patch. > > -- > Mario Gonzalez > EDB: https://www.enterprisedb.com -- Mario Gonzalez EDB: https://www.enterprisedb.com
From 3e1e277f34e3d8a2bfd7df06be4e56683fab6199 Mon Sep 17 00:00:00 2001 From: Mario Gonzalez <[email protected]> Date: Thu, 2 Jul 2026 23:30:34 -0400 Subject: [PATCH v1] Replace of strncpy on xactdesc.c ParsePrepareRecord function parses data from a xl_xact_prepare struct. During its execution, it uses strncpy() to copy some data over. This call can be replaced by strlcpy() from src/port/. Despite the space in memory used as a destination is zero'ed beforehand using the memset below, the rest of functions are already using strlcpy: memset(parsed, 0, sizeof(*parsed)); It seems like accidentally 'n' was typed when 'l' was supposed to be used. The change with strncpy was introduced in 1eb6d6527aae in twophase.c and then moved to xaxtdesc.c in 7b8a899bdeb. --- src/backend/access/rmgrdesc/xactdesc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 = xlrec->nabortstats; parsed->nmsgs = xlrec->ninvalmsgs; - strncpy(parsed->twophase_gid, bufptr, xlrec->gidlen); + strlcpy(parsed->twophase_gid, bufptr, sizeof(parsed->twophase_gid)); bufptr += MAXALIGN(xlrec->gidlen); parsed->subxacts = (TransactionId *) bufptr; -- 2.47.3
