XLogInsert() of dangling pointer while logging replica identity

Started by Stas Kelvichabout 7 years ago3 messageshackers
Jump to latest
#1Stas Kelvich
s.kelvich@postgrespro.ru

Hi, hackers.

It seems that heapam.c:3082 calls XLogRegisterData() with an argument
allocated on stack, but following call to XLogInsert() happens after
end of context for that variable.
Issue spotted by clang's AddressSanitizer. Fix attached.

--
Stas Kelvich
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

Attachments:

0001-Fix-use-after-scope.patchapplication/octet-stream; name=0001-Fix-use-after-scope.patch; x-unix-mode=0644Download+1-3
#2Michael Paquier
michael@paquier.xyz
In reply to: Stas Kelvich (#1)
Re: XLogInsert() of dangling pointer while logging replica identity

On Thu, Jan 31, 2019 at 11:51:36PM +0300, Stas Kelvich wrote:

It seems that heapam.c:3082 calls XLogRegisterData() with an argument
allocated on stack, but following call to XLogInsert() happens after
end of context for that variable.
Issue spotted by clang's AddressSanitizer. Fix attached.

Oh, good catch. Committed and back-patched down to 9.4.
--
Michael

#3Andres Freund
andres@anarazel.de
In reply to: Michael Paquier (#2)
Re: XLogInsert() of dangling pointer while logging replica identity

On 2019-02-01 10:38:49 +0900, Michael Paquier wrote:

On Thu, Jan 31, 2019 at 11:51:36PM +0300, Stas Kelvich wrote:

It seems that heapam.c:3082 calls XLogRegisterData() with an argument
allocated on stack, but following call to XLogInsert() happens after
end of context for that variable.
Issue spotted by clang's AddressSanitizer. Fix attached.

Oh, good catch. Committed and back-patched down to 9.4.

Thanks Stas and Michael!