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

From: Richard Guo <guofenglinux(at)gmail(dot)com>
To: Ranier Vilela <ranier(dot)vf(at)gmail(dot)com>
Cc: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Avoid incomplete copy string (src/backend/access/transam/xlog.c)
Date: 2024-06-24 02:56:20
Message-ID: CAMbWs4-f4D425C73p0WPBYb2qpiGZyJGvivxS15rEz_igR8vMQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Jun 24, 2024 at 7:51 AM Ranier Vilela <ranier(dot)vf(at)gmail(dot)com> wrote:
> In src/include/access/xlogbackup.h, the field *name*
> has one byte extra to store null-termination.
>
> But, in the function *do_pg_backup_start*,
> I think that is a mistake in the line (8736):
>
> memcpy(state->name, backupidstr, strlen(backupidstr));
>
> 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?

Thanks
Richard

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Yugo NAGATA 2024-06-24 03:27:28 Re: Avoid incomplete copy string (src/backend/access/transam/xlog.c)
Previous Message Masahiro.Ikeda 2024-06-24 02:52:10 RE: Improve EXPLAIN output for multicolumn B-Tree Index