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

From: Ranier Vilela <ranier(dot)vf(at)gmail(dot)com>
To: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Avoid incomplete copy string (src/backend/access/transam/xlog.c)
Date: 2024-06-23 23:51:26
Message-ID: CAEudQApAsbLsQ+gGiw-hT+JwGhgogFa_=5NUkgFO6kOPxyNidQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi.

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.

So, I think this can result in errors,
like in the function *build_backup_content*
(src/backend/access/transam/xlogbackup.c)
Where *appendStringInfo* expects a string with null-termination.

appendStringInfo(result, "LABEL: %s\n", state->name);

To fix, copy strlen size plus one byte, to include the null-termination.

Trivial patch attached.

best regards,
Ranier Vilela

Attachment Content-Type Size
avoid-incomplete-copy-string-do_pg_backup_start.patch application/octet-stream 572 bytes

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Fabrízio de Royes Mello 2024-06-24 00:08:47 Re: Avoid incomplete copy string (src/backend/access/transam/xlog.c)
Previous Message Michael Paquier 2024-06-23 23:46:30 Re: Add pg_get_acl() function get the ACL for a database object