Skip to content

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

Description

@jackalcooper

in tty.zig

    pub fn detect(file: File) Config {
        const force_color: ?bool = if (builtin.os.tag == .wasi)
            null // wasi does not support environment variables
        else if (process.hasNonEmptyEnvVarConstant("NO_COLOR"))
            false
        else if (process.hasNonEmptyEnvVarConstant("CLICOLOR_FORCE"))
            true
        else
            null;

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

gdb

Thread 6 "2_scheduler" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffb3b94640 (LWP 3483)]
0x00007fffaba5032e in posix.getenv (key=...) from /home/runner/work/kinda/kinda/kinda_example/_build/test/lib/kinda_example/priv/lib/libKindaExampleNIF.so
#0  0x00007fffaba5032e in posix.getenv (key=...)
   from /home/runner/work/kinda/kinda/kinda_example/_build/test/lib/kinda_example/priv/lib/libKindaExampleNIF.so
#1  0x00007fffaba63e8b in process.hasNonEmptyEnvVarConstant__anon_11739 (
    key=...)
   from /home/runner/work/kinda/kinda/kinda_example/_build/test/lib/kinda_example/priv/lib/libKindaExampleNIF.so
#2  0x00007fffaba340a4 in Io.tty.Config.detect (file=...)
   from /home/runner/work/kinda/kinda/kinda_example/_build/test/lib/kinda_example/priv/lib/libKindaExampleNIF.so
#3  0x00007fffaba0e2e8 in Io.tty.detectConfig (file=...)
   from /home/runner/work/kinda/kinda/kinda_example/_build/test/lib/kinda_example/priv/lib/libKindaExampleNIF.so
#4  0x00007fffabb0e927 in builtin.StackTrace.format (self=..., 
    writer=0x7fffb3b8f5d0)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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