VirtualBox

Changeset 96519 in vbox


Ignore:
Timestamp:
Aug 26, 2022 12:20:35 PM (3 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
153384
Message:

IPRT/thread-posix.cpp: Try initialize g_SelfKey to a non-valid value to prevent accidental use of someone else's data. bugref:10261

File:
1 edited

Legend:

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

    r96407 r96519  
    4141#define LOG_GROUP RTLOGGROUP_THREAD
    4242#include <errno.h>
     43#include <limits.h>
    4344#include <pthread.h>
    4445#include <signal.h>
     
    99100*   Global Variables                                                                                                             *
    100101*********************************************************************************************************************************/
    101 /** The pthread key in which we store the pointer to our own PRTTHREAD structure. */
    102 static pthread_key_t    g_SelfKey;
     102/** The pthread key in which we store the pointer to our own PRTTHREAD structure.
     103 * @note There is a defined NIL value here, nor can we really assume this is an
     104 *       integer.  However, zero is a valid key on Linux, so we get into trouble
     105 *       if we accidentally use it uninitialized.
     106 *
     107 *       So, we ASSUME it's a integer value and the valid range is in approx 0
     108 *       to PTHREAD_KEYS_MAX.  Solaris has at least one negative value (-1)
     109 *       defined.  Thus, we go for 16 MAX values below zero and keep our fingers
     110 *       cross that it will always be an invalid key value everywhere...
     111 *
     112 *       See also NIL_RTTLS, which is -1.
     113 */
     114static pthread_key_t    g_SelfKey = (pthread_key_t)(-PTHREAD_KEYS_MAX * 16);
    103115#ifdef RTTHREAD_POSIX_WITH_POKE
    104116/** The signal we use for poking threads.
Note: See TracChangeset for help on using the changeset viewer.

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