Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit13abc1f

Browse files
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.us
1 parent9dbf8ab commit13abc1f

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

‎src/backend/utils/error/elog.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1578,7 +1578,21 @@ CopyErrorData(void)
15781578
newedata= (ErrorData*)palloc(sizeof(ErrorData));
15791579
memcpy(newedata,edata,sizeof(ErrorData));
15801580

1581-
/* Make copies of separately-allocated fields */
1581+
/*
1582+
* Make copies of separately-allocated strings. Note that we copy even
1583+
* theoretically-constant strings such as filename. This is because those
1584+
* could point into JIT-created code segments that might get unloaded at
1585+
* transaction cleanup. In some cases we need the copied ErrorData to
1586+
* survive transaction boundaries, so we'd better copy those strings too.
1587+
*/
1588+
if (newedata->filename)
1589+
newedata->filename=pstrdup(newedata->filename);
1590+
if (newedata->funcname)
1591+
newedata->funcname=pstrdup(newedata->funcname);
1592+
if (newedata->domain)
1593+
newedata->domain=pstrdup(newedata->domain);
1594+
if (newedata->context_domain)
1595+
newedata->context_domain=pstrdup(newedata->context_domain);
15821596
if (newedata->message)
15831597
newedata->message=pstrdup(newedata->message);
15841598
if (newedata->detail)
@@ -1591,6 +1605,8 @@ CopyErrorData(void)
15911605
newedata->context=pstrdup(newedata->context);
15921606
if (newedata->backtrace)
15931607
newedata->backtrace=pstrdup(newedata->backtrace);
1608+
if (newedata->message_id)
1609+
newedata->message_id=pstrdup(newedata->message_id);
15941610
if (newedata->schema_name)
15951611
newedata->schema_name=pstrdup(newedata->schema_name);
15961612
if (newedata->table_name)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp