From: David Steele <david@pgmasters.net>
To: Tom Lane <tgl@sss.pgh.pa.us>
To: Teodor Sigaev <teodor@sigaev.ru>
Cc: pgsql-committers@lists.postgresql.org
Subject: Re: pgsql: Exclude unlogged tables from base backups
Date: Sun, 25 Mar 2018 15:10:03 -0400
Message-ID: <8d57c3ba-d44b-a8eb-7a91-c0b6156240fd@pgmasters.net> (raw)
In-Reply-To: <14453.1522001792@sss.pgh.pa.us>
References: <E1ezPKi-00081N-FP@gemulon.postgresql.org>
<14453.1522001792@sss.pgh.pa.us>
On 3/25/18 2:16 PM, Tom Lane wrote:
> Teodor Sigaev <teodor@sigaev.ru> writes:
>> Exclude unlogged tables from base backups
>
> Buildfarm member skink (valgrind) has reported this during its last couple
> of runs:
>
> 2018-03-24 03:18:23.409 UTC [17302] 010_pg_basebackup.pl LOG: received replication command: BASE_BACKUP LABEL 'pg_basebackup base backup' NOWAIT TABLESPACE_MAP
> ==17302== VALGRINDERROR-BEGIN
> ==17302== Conditional jump or move depends on uninitialised value(s)
> ==17302== at 0x4C2FD88: strlen (vg_replace_strmem.c:458)
> ==17302== by 0x6FBA3AB: vfprintf (vfprintf.c:1643)
> ==17302== by 0x6FE19AF: vsnprintf (vsnprintf.c:114)
> ==17302== by 0x6FC0F6E: snprintf (snprintf.c:33)
> ==17302== by 0x4A3C97: sendDir (basebackup.c:1060)
> ==17302== by 0x4A40C6: sendDir (basebackup.c:1221)
> ==17302== by 0x4A52B2: sendTablespace (basebackup.c:937)
> ==17302== by 0x4A5740: perform_base_backup (basebackup.c:313)
> ==17302== by 0x4A635C: SendBaseBackup (basebackup.c:710)
> ==17302== by 0x49FCF2: exec_replication_command (walsender.c:1520)
> ==17302== by 0x4F61CE: PostgresMain (postgres.c:4143)
> ==17302== by 0x4712ED: BackendRun (postmaster.c:4409)
> ==17302== Uninitialised value was created by a stack allocation
> ==17302== at 0x4A38EA: sendDir (basebackup.c:957)
> ==17302==
> ==17302== VALGRINDERROR-END
> 2018-03-24 03:18:26.127 UTC [17302] 010_pg_basebackup.pl DEBUG: contents of directory "pg_serial" excluded from backup
>
> I might be wrong to blame that on this patch, but nothing else has
> touched basebackup.c lately.
Sure looks like it deserves the blame -- the error is occurring right in
the new code.
I think skink is using large values for rel oids and that has exposed a
bug. The strncpy doesn't zero terminate the string if the oid has the
max number of characters. At least, I was able to reproduce under those
circumstances.
The attached should fix it.
Regards,
--
-David
david@pgmasters.net
Attachments:basebackup.patch (text/plain, 619B) downloaddiff --git a/src/backend/replication/basebackup.c b/src/backend/replication/basebackup.cindex eb6eb7206d..e368943494 100644--- a/src/backend/replication/basebackup.c+++ b/src/backend/replication/basebackup.c@@ -1056,6 +1056,7 @@ sendDir(const char *path, int basepathlen, bool sizeonly, List *tablespaces,
* If any other type of fork, check if there is an init fork
* with the same OID. If so, the file can be excluded.
*/
+ memset(relOid, 0, sizeof(relOid));
strncpy(relOid, de->d_name, relOidChars);
snprintf(initForkFile, sizeof(initForkFile), "%s/%s_init",
path, relOid);
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-committers@postgresql.org
Cc: david@pgmasters.net, tgl@sss.pgh.pa.us, teodor@sigaev.ru
Subject: Re: pgsql: Exclude unlogged tables from base backups
In-Reply-To: <8d57c3ba-d44b-a8eb-7a91-c0b6156240fd@pgmasters.net>
References: <E1ezPKi-00081N-FP@gemulon.postgresql.org> <14453.1522001792@sss.pgh.pa.us> <8d57c3ba-d44b-a8eb-7a91-c0b6156240fd@pgmasters.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox