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

Commit86fac88

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 parente9c8747 commit86fac88

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
@@ -1492,7 +1492,21 @@ CopyErrorData(void)
14921492
newedata= (ErrorData*)palloc(sizeof(ErrorData));
14931493
memcpy(newedata,edata,sizeof(ErrorData));
14941494

1495-
/* Make copies of separately-allocated fields */
1495+
/*
1496+
* Make copies of separately-allocated strings. Note that we copy even
1497+
* theoretically-constant strings such as filename. This is because those
1498+
* could point into JIT-created code segments that might get unloaded at
1499+
* transaction cleanup. In some cases we need the copied ErrorData to
1500+
* survive transaction boundaries, so we'd better copy those strings too.
1501+
*/
1502+
if (newedata->filename)
1503+
newedata->filename=pstrdup(newedata->filename);
1504+
if (newedata->funcname)
1505+
newedata->funcname=pstrdup(newedata->funcname);
1506+
if (newedata->domain)
1507+
newedata->domain=pstrdup(newedata->domain);
1508+
if (newedata->context_domain)
1509+
newedata->context_domain=pstrdup(newedata->context_domain);
14961510
if (newedata->message)
14971511
newedata->message=pstrdup(newedata->message);
14981512
if (newedata->detail)
@@ -1505,6 +1519,8 @@ CopyErrorData(void)
15051519
newedata->context=pstrdup(newedata->context);
15061520
if (newedata->backtrace)
15071521
newedata->backtrace=pstrdup(newedata->backtrace);
1522+
if (newedata->message_id)
1523+
newedata->message_id=pstrdup(newedata->message_id);
15081524
if (newedata->schema_name)
15091525
newedata->schema_name=pstrdup(newedata->schema_name);
15101526
if (newedata->table_name)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp