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

Commit07d66d3

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 parentb5b418b commit07d66d3

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
@@ -1738,7 +1738,21 @@ CopyErrorData(void)
17381738
newedata= (ErrorData*)palloc(sizeof(ErrorData));
17391739
memcpy(newedata,edata,sizeof(ErrorData));
17401740

1741-
/* Make copies of separately-allocated fields */
1741+
/*
1742+
* Make copies of separately-allocated strings. Note that we copy even
1743+
* theoretically-constant strings such as filename. This is because those
1744+
* could point into JIT-created code segments that might get unloaded at
1745+
* transaction cleanup. In some cases we need the copied ErrorData to
1746+
* survive transaction boundaries, so we'd better copy those strings too.
1747+
*/
1748+
if (newedata->filename)
1749+
newedata->filename=pstrdup(newedata->filename);
1750+
if (newedata->funcname)
1751+
newedata->funcname=pstrdup(newedata->funcname);
1752+
if (newedata->domain)
1753+
newedata->domain=pstrdup(newedata->domain);
1754+
if (newedata->context_domain)
1755+
newedata->context_domain=pstrdup(newedata->context_domain);
17421756
if (newedata->message)
17431757
newedata->message=pstrdup(newedata->message);
17441758
if (newedata->detail)
@@ -1751,6 +1765,8 @@ CopyErrorData(void)
17511765
newedata->context=pstrdup(newedata->context);
17521766
if (newedata->backtrace)
17531767
newedata->backtrace=pstrdup(newedata->backtrace);
1768+
if (newedata->message_id)
1769+
newedata->message_id=pstrdup(newedata->message_id);
17541770
if (newedata->schema_name)
17551771
newedata->schema_name=pstrdup(newedata->schema_name);
17561772
if (newedata->table_name)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp