Re: pg_dump: Fix dangling pointer in EndCompressorZstd() - Mailing list pgsql-hackers

From Ashutosh Bapat
Subject Re: pg_dump: Fix dangling pointer in EndCompressorZstd()
Date
Msg-id CAExHW5uEAPLhaawqjZOU+yGjS1h8L_U0QGvrx+xA0Y3gF3hdSw@mail.gmail.com
Whole thread Raw
In response to pg_dump: Fix dangling pointer in EndCompressorZstd()  (Alexander Kuznetsov <kuznetsovam@altlinux.org>)
Responses Re: pg_dump: Fix dangling pointer in EndCompressorZstd()
List pgsql-hackers
On Wed, Apr 16, 2025 at 1:57 PM Alexander Kuznetsov
<kuznetsovam@altlinux.org> wrote:
>
> Hello everyone,
>
> We've found that EndCompressorZstd() doesn't set cs->private_data to NULL after pg_free(),
> unlike other EndCompressor implementations.
> While this doesn't currently cause issues (as the pointer soon gets reassigned),
> we recommend fixing this to maintain consistency with other implementations and prevent potential future issues.
>
> The patch is attached, would appreciate your thoughts on this change.

Thanks for the patch.

The next thing that happens in EndCompressor() is freeing cs itself.
So cs->private_data is not used anywhere, so no harm in the current
code. But it's better to set to NULL since EndCompressorZstd()
wouldn't know how it's being accessed after returning from there. The
other implementation of CompressionState::end() EndCompressorGzip()
calls DeflateCompressorEnd() which also sets cs->private_data
explicitly. So should EndCompressorZstd().

--
Best Wishes,
Ashutosh Bapat



pgsql-hackers by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: not null constraints, again
Next
From: Tender Wang
Date:
Subject: Re: not null constraints, again