forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit5d6c64d
committed
Avoid crashing when a JIT-inlined backend function throws an error.
errfinish() assumes that the __FUNC__ and __FILE__ arguments it'spassed are compile-time constant strings that can just be pointedto rather than physically copied. However, it's possible for LLVMto generate code in which those pointers point into a dynamicallyloaded code segment. If that segment gets unloaded before we'redone with the ErrorData struct, we have dangling pointers thatwill lead to SIGSEGV. In simple cases that won't happen, because wewon't unload LLVM code before end of transaction. But it's possibleto happen if the error is thrown within end-of-transaction code run by_SPI_commit or _SPI_rollback, because since commit2e51781 thosefunctions clean up by ending the transaction and starting a new one.Rather than fixing this by adding pstrdup() overhead to everyelog/ereport sequence, let's fix it by copying the risky pointersin CopyErrorData(). That solves it for _SPI_commit/_SPI_rollbackbecause they use that function to preserve the error data acrossthe transaction end/restart sequence; and it seems likely thatany other code doing something similar would need to do that too.I'm suspicious that this behavior amounts to an LLVM bug (or abug in our use of it?), because it implies that string constantreferences that should be pointer-equal according to a naiveunderstanding of C semantics will sometimes not be equal.However, even if it is a bug and someday gets fixed, we'll haveto cope with the current behavior for a long time to come.Report and patch by me. Back-patch to all supported branches.Discussion:https://postgr.es/m/1565654.1719425368@sss.pgh.pa.us1 parentcbfbda7 commit5d6c64d
1 file changed
+17
-1
lines changedLines changed: 17 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1743 | 1743 |
| |
1744 | 1744 |
| |
1745 | 1745 |
| |
1746 |
| - | |
| 1746 | + | |
| 1747 | + | |
| 1748 | + | |
| 1749 | + | |
| 1750 | + | |
| 1751 | + | |
| 1752 | + | |
| 1753 | + | |
| 1754 | + | |
| 1755 | + | |
| 1756 | + | |
| 1757 | + | |
| 1758 | + | |
| 1759 | + | |
| 1760 | + | |
1747 | 1761 |
| |
1748 | 1762 |
| |
1749 | 1763 |
| |
| |||
1756 | 1770 |
| |
1757 | 1771 |
| |
1758 | 1772 |
| |
| 1773 | + | |
| 1774 | + | |
1759 | 1775 |
| |
1760 | 1776 |
| |
1761 | 1777 |
| |
|
0 commit comments
Comments
(0)