public inbox for [email protected]
help / color / mirror / Atom feedFrom: Mario González Troncoso <[email protected]>
To: Daniel Gustafsson <[email protected]>
Cc: PostgreSQL Hackers <[email protected]>
Subject: Re: Possible replace of strncpy on xactdesc.c
Date: Mon, 6 Jul 2026 18:31:44 -0400
Message-ID: <CAFsReFVg--+gp8T_QzKos6aUPZRfOupBz=d=1sHg2wc8KkO_WQ@mail.gmail.com> (raw)
In-Reply-To: <CAFsReFWd5dmy16S5Umsn=peurgpiph0fd4H1BmLtbrMzC_OvPA@mail.gmail.com>
References: <CAFsReFVjinOs0tqbb1C_LgSrpemDNgA3zQembNytOfJyaktHFw@mail.gmail.com>
<[email protected]>
<CAFsReFWd5dmy16S5Umsn=peurgpiph0fd4H1BmLtbrMzC_OvPA@mail.gmail.com>
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
Attachments:
[text/x-patch] v1-0001-Replace-of-strncpy-on-xactdesc.c.patch (1.5K, ../CAFsReFVg--+gp8T_QzKos6aUPZRfOupBz=d=1sHg2wc8KkO_WQ@mail.gmail.com/2-v1-0001-Replace-of-strncpy-on-xactdesc.c.patch)
download | inline diff:
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
view thread (7+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected]
Subject: Re: Possible replace of strncpy on xactdesc.c
In-Reply-To: <CAFsReFVg--+gp8T_QzKos6aUPZRfOupBz=d=1sHg2wc8KkO_WQ@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox