VirtualBox

Changeset 96582 in vbox for trunk/src/VBox/Runtime/r3


Ignore:
Timestamp:
Sep 2, 2022 3:22:35 PM (2 years ago)
Author:
vboxsync
Message:

IPRT: Darwin's libpthread doesn't validate pthread_getspecific input, so we have to do that for them to avoid misbehaviour if called before initialization. bugref:10261

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/posix/thread-posix.cpp

    r96519 r96582  
    664664RTDECL(RTTHREAD) RTThreadSelf(void)
    665665{
    666     PRTTHREADINT pThread = (PRTTHREADINT)pthread_getspecific(g_SelfKey);
    667666    /** @todo import alien threads? */
    668     return pThread;
     667#if defined(RT_OS_DARWIN)
     668    /* On darwin, there seems to be input checking with pthread_getspecific.
     669       So, we must prevent using g_SelfKey before rtThreadNativeInit has run,
     670       otherwise we might crash or starting working with total garbage pointer
     671       values here (see _os_tsd_get_direct in znu/libsyscall/os/tsd.h).
     672
     673       Now, since the init value is a "negative" one, we just have to check
     674       that it's positive or zero before calling the API. */
     675    if (RT_LIKELY((intptr_t)g_SelfKey >= 0))
     676        return (PRTTHREADINT)pthread_getspecific(g_SelfKey);
     677    return NIL_RTTHREAD;
     678#else
     679    return (PRTTHREADINT)pthread_getspecific(g_SelfKey);
     680#endif
    669681}
    670682
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette