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

Commit1f9bf05

Browse files
committed
Use correct text domain for errcontext() appearing within ereport().
The mechanism added in commitdbdf967for associating the correct translation domain with errcontext stringspotentially fails in cases where errcontext() is used within an ereport()macro. Such usage was not originally envisioned for errcontext(), but wedo have a few places that do it. In this situation, the intended commaexpression becomes just a couple of arguments to errfinish(), which thecompiler might choose to evaluate right-to-left.Fortunately, in such cases the textdomain for the errcontext string mustbe the same as for the surrounding ereport. So we can fix this by lettingerrstart initialize context_domain along with domain; then it will havethe correct value no matter which order the calls occur in. (Note thaterror stack callback functions are not invoked until errfinish, so normalusage of errcontext won't affect what happens for errcontext calls withinthe ereport macro.)In passing, make sure that errcontext calls within the main backend setcontext_domain to something non-NULL. This isn't a live bug becauseNULL would select the current textdomain() setting which should be theright thing anyway --- but it seems better to handle this completelyconsistently with the regular domain field.Per report from Dmitry Voronin. Backpatch to 9.3; before that, therewasn't any attempt to ensure that errcontext strings were translatedin an appropriate domain.
1 parent1bf4a84 commit1f9bf05

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,8 @@ errstart(int elevel, const char *filename, int lineno,
378378
edata->funcname=funcname;
379379
/* the default text domain is the backend's */
380380
edata->domain=domain ?domain :PG_TEXTDOMAIN("postgres");
381+
/* initialize context_domain the same way (see set_errcontext_domain()) */
382+
edata->context_domain=edata->domain;
381383
/* Select default errcode based on elevel */
382384
if (elevel >=ERROR)
383385
edata->sqlerrcode=ERRCODE_INTERNAL_ERROR;
@@ -728,7 +730,7 @@ errcode_for_socket_access(void)
728730
char *fmtbuf; \
729731
StringInfoDatabuf; \
730732
/* Internationalize the error format string */ \
731-
if (translateit&& !in_error_recursion_trouble()) \
733+
if ((translateit)&& !in_error_recursion_trouble()) \
732734
fmt=dgettext((domain),fmt); \
733735
/* Expand %m in format string */ \
734736
fmtbuf=expand_fmt_string(fmt,edata); \
@@ -1048,6 +1050,16 @@ errcontext_msg(const char *fmt,...)
10481050
* translate it. Instead, each errcontext_msg() call should be preceded by
10491051
* a set_errcontext_domain() call to specify the domain. This is usually
10501052
* done transparently by the errcontext() macro.
1053+
*
1054+
* Although errcontext is primarily meant for use at call sites distant from
1055+
* the original ereport call, there are a few places that invoke errcontext
1056+
* within ereport. The expansion of errcontext as a comma expression calling
1057+
* set_errcontext_domain then errcontext_msg is problematic in this case,
1058+
* because the intended comma expression becomes two arguments to errfinish,
1059+
* which the compiler is at liberty to evaluate in either order. But in
1060+
* such a case, the set_errcontext_domain calls must be selecting the same
1061+
* TEXTDOMAIN value that the errstart call did, so order does not matter
1062+
* so long as errstart initializes context_domain along with domain.
10511063
*/
10521064
int
10531065
set_errcontext_domain(constchar*domain)
@@ -1057,7 +1069,8 @@ set_errcontext_domain(const char *domain)
10571069
/* we don't bother incrementing recursion_depth */
10581070
CHECK_STACK_DEPTH();
10591071

1060-
edata->context_domain=domain;
1072+
/* the default text domain is the backend's */
1073+
edata->context_domain=domain ?domain :PG_TEXTDOMAIN("postgres");
10611074

10621075
return0;/* return value does not matter */
10631076
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp