Re: PostgreSQL crashes with SIGSEGV
Peter Geoghegan <pg@bowt.ie>
From: Peter Geoghegan <pg@bowt.ie>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Aleksandr Parfenov <a.parfenov@postgrespro.ru>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2018-02-23T00:22:47Z
Lists: pgsql-bugs, pgsql-hackers
Attachments
- REL9_6_STABLE-fix-double-free-tuplesort.patch (text/x-patch) patch
- REL_10_STABLE-fix-double-free-tuplesort.patch (text/x-patch) patch
- REL9_5_STABLE-fix-double-free-tuplesort.patch (text/x-patch) patch
- master-fix-double-free-tuplesort.patch (text/x-patch) patch
On Mon, Feb 12, 2018 at 6:15 PM, Peter Geoghegan <pg@bowt.ie> wrote: > * For 9.5 and 9.6, the approach taken in bugfix commit d8589946d > should be taken even further -- we should always copy. Moreover, we > should always copy within tuplesort_getdatum(), for the same reasons. > > * For 9.5, 9.6, 10, and master, we should make sure that > tuplesort_getdatum() uses the caller's memory context. The fact that > it doesn't already do so seems like a simple oversight. We should do > this to be consistent with tuplesort_gettupleslot(). (This isn't > critical, but seems like a good idea.) > > * For 9.5, 9.6, 10, and master, we should adjust some comments from > tuplesort_getdatum() callers, so that they no longer say that > tuplesort datum tuple memory lives in tuplesort context. That won't be > true anymore. Attached patches do it that way. I'm happy with what I came up with, which is a lot simpler than my first approach. The extra copying seems likely to be well worth it, since it is fairly isolated in practice, especially on 9.6. There is no extra copying from v10+, since they don't need the first fix at all. -- Peter Geoghegan
Commits
-
Fix actual and potential double-frees around tuplesort usage.
- c2d4eb1b1fa2 11.0 landed
- e4ff711582b1 9.5.13 landed
- c98f218fbf5a 10.4 landed
- 90decdba3786 9.6.9 landed
-
Allow the built-in ordered-set aggregates to share transition state.
- be0ebb65f512 11.0 cited
-
Avoid integer overflow while sifting-up a heap in tuplesort.c.
- 512f67c8d02c 10.0 cited
-
Allow avoiding tuple copy within tuplesort_gettupleslot().
- fa117ee40330 10.0 cited
-
Remove should_free arguments to tuplesort routines.
- 3856cf9607f4 10.0 cited
-
Fix use-after-free around DISTINCT transition function calls.
- a5f0bd77a2fa 9.6.1 cited
- d8589946ddd5 10.0 cited
-
Reuse abbreviated keys in ordered [set] aggregates.
- f1f5ec1efafe 9.6.0 cited