Skip to content

StackTrace.format is not thread-safe due to the usage of getenv in tty detect #25473

Description

@jackalcooper

in tty.zig

pubfndetect(file: File) Config {
constforce_color: ?bool=if (builtin.os.tag==.wasi)
null// wasi does not support environment variableselseif (process.hasNonEmptyEnvVarConstant("NO_COLOR"))
falseelseif (process.hasNonEmptyEnvVarConstant("CLICOLOR_FORCE"))
trueelsenull;

process.hasNonEmptyEnvVarConstant calls posix.getenv(key) which is not thread-safe on glibc linux

gdb

Thread6"2_scheduler"receivedsignalSIGSEGV, Segmentationfault.
[SwitchingtoThread0x7fffb3b94640 (LWP3483)]
0x00007fffaba5032einposix.getenv (key=...) from/home/runner/work/kinda/kinda/kinda_example/_build/test/lib/kinda_example/priv/lib/libKindaExampleNIF.so
#00x00007fffaba5032einposix.getenv (key=...)
from/home/runner/work/kinda/kinda/kinda_example/_build/test/lib/kinda_example/priv/lib/libKindaExampleNIF.so
#10x00007fffaba63e8binprocess.hasNonEmptyEnvVarConstant__anon_11739 (
key=...)
from/home/runner/work/kinda/kinda/kinda_example/_build/test/lib/kinda_example/priv/lib/libKindaExampleNIF.so
#20x00007fffaba340a4inIo.tty.Config.detect (file=...)
from/home/runner/work/kinda/kinda/kinda_example/_build/test/lib/kinda_example/priv/lib/libKindaExampleNIF.so
#30x00007fffaba0e2e8inIo.tty.detectConfig (file=...)
from/home/runner/work/kinda/kinda/kinda_example/_build/test/lib/kinda_example/priv/lib/libKindaExampleNIF.so
#40x00007fffabb0e927inbuiltin.StackTrace.format (self=..., writer=0x7fffb3b8f5d0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behavioros-linuxLinuxstandard libraryThis issue involves writing Zig code for the standard library.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions