Re: Avoid incomplete copy string (src/backend/access/transam/xlog.c)

From: Daniel Gustafsson <daniel(at)yesql(dot)se>
To: Yugo NAGATA <nagata(at)sraoss(dot)co(dot)jp>
Cc: Ranier Vilela <ranier(dot)vf(at)gmail(dot)com>, Richard Guo <guofenglinux(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Avoid incomplete copy string (src/backend/access/transam/xlog.c)
Date: 2024-07-01 08:52:22
Message-ID: 50BF501F-58BA-450B-A1FA-B083D8EFCEE1@yesql.se
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> On 27 Jun 2024, at 06:01, Yugo NAGATA <nagata(at)sraoss(dot)co(dot)jp> wrote:
>> Em dom., 23 de jun. de 2024 às 23:56, Richard Guo <guofenglinux(at)gmail(dot)com>
>> escreveu:
>>> On Mon, Jun 24, 2024 at 7:51 AM Ranier Vilela <ranier(dot)vf(at)gmail(dot)com> wrote:

>>>> memcpy with strlen does not copy the whole string.
>>>> strlen returns the exact length of the string, without
>>>> the null-termination.
>>>
>>> I noticed that the two callers of do_pg_backup_start both allocate
>>> BackupState with palloc0. Can we rely on this to ensure that the
>>> BackupState.name is initialized with null-termination?
>>>
>> I do not think so.

In this case we can, we do that today..

> However, I wonder it is better to use strlcpy without assuming such the good
> manner of callers.

..that being said I agree that it seems safer to use strlcpy() here.

--
Daniel Gustafsson

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message David Rowley 2024-07-01 08:55:44 Make tuple deformation faster
Previous Message Daniel Gustafsson 2024-07-01 08:45:53 Re: Is missing LOGIN Event on Trigger Firing Matrix ?