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

Commitf686ae8

Browse files
committed
Add workaround to make ubsan and ps_status.c compatible
At least on linux, set_ps_display() breaks /proc/$pid/environ. The sanitizer'shelper library uses /proc/$pid/environ to implement getenv(), as it wants towork independent of libc. When just using undefined and alignment sanitizers,the sanitizer library is only initialized when the first error occurs, bywhich time we've often already called set_ps_display(), preventing thesanitizer libraries from seeing the options.We can work around that by defining __ubsan_default_options, a weak symbollibsanitizer uses to get defaults from the application, and returngetenv("UBSAN_OPTIONS"). But only if main already was reached, so that wedon't end up relying on a not-yet-working getenv().As it's just a function that won't get called when not running a sanitizer, itdoesn't seem necessary to make compilation of the function conditional.Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>Discussion:https://postgr.es/m/20220323173537.ll7klrglnp4gn2um@alap3.anarazel.de
1 parentaeaaf52 commitf686ae8

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

‎src/backend/main/main.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343

4444

4545
constchar*progname;
46+
staticboolreached_main= false;
4647

4748

4849
staticvoidstartup_hacks(constchar*progname);
@@ -59,6 +60,8 @@ main(int argc, char *argv[])
5960
{
6061
booldo_check_root= true;
6162

63+
reached_main= true;
64+
6265
/*
6366
* If supported on the current platform, set up a handler to be called if
6467
* the backend/postmaster crashes with a fatal signal or exception.
@@ -420,3 +423,30 @@ check_root(const char *progname)
420423
}
421424
#endif/* WIN32 */
422425
}
426+
427+
/*
428+
* At least on linux, set_ps_display() breaks /proc/$pid/environ. The
429+
* sanitizer library uses /proc/$pid/environ to implement getenv() as it wants
430+
* to work independent of libc. When just using undefined and alignment
431+
* sanitizers, the sanitizer library is only initialized when the first error
432+
* occurs, by which time we've often already called set_ps_display(),
433+
* preventing the sanitizer libraries from seeing the options.
434+
*
435+
* We can work around that by defining __ubsan_default_options, a weak symbol
436+
* libsanitizer uses to get defaults from the application, and return
437+
* getenv("UBSAN_OPTIONS"). But only if main already was reached, so that we
438+
* don't end up relying on a not-yet-working getenv().
439+
*
440+
* As this function won't get called when not running a sanitizer, it doesn't
441+
* seem necessary to only compile it conditionally.
442+
*/
443+
constchar*__ubsan_default_options(void);
444+
constchar*
445+
__ubsan_default_options(void)
446+
{
447+
/* don't call libc before it's guaranteed to be initialized */
448+
if (!reached_main)
449+
return"";
450+
451+
returngetenv("UBSAN_OPTIONS");
452+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp