Avoid incomplete copy string (src/backend/access/transam/xlog.c) - Mailing list pgsql-hackers

From Ranier Vilela
Subject Avoid incomplete copy string (src/backend/access/transam/xlog.c)
Date
Msg-id CAEudQApAsbLsQ+gGiw-hT+JwGhgogFa_=5NUkgFO6kOPxyNidQ@mail.gmail.com
Whole thread Raw
Responses Re: Avoid incomplete copy string (src/backend/access/transam/xlog.c)
Re: Avoid incomplete copy string (src/backend/access/transam/xlog.c)
List 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

pgsql-hackers by date:

Previous
From: Michael Paquier
Date:
Subject: Re: Add pg_get_acl() function get the ACL for a database object
Next
From: Fabrízio de Royes Mello
Date:
Subject: Re: Avoid incomplete copy string (src/backend/access/transam/xlog.c)