diff options
author | kitty <kitty@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2007-03-18 02:39:03 +0000 |
---|---|---|
committer | kitty <kitty@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2007-03-18 02:39:03 +0000 |
commit | 4fe14ad59676ee0cd6f54bbd38d714cce3da558e (patch) | |
tree | 8815ce3b3a85c3c4285429295f338e00ea4497f4 | |
parent | 7ab0cd4f07e54b5ad7fe9fffdb52c4d5d4069e0d (diff) | |
download | ATCD-4fe14ad59676ee0cd6f54bbd38d714cce3da558e.tar.gz |
ChangeLogTag: Sun Mar 18 02:09:31 UTC 2007 Krishnakumar B <kitty@nospam.invalid.domain>
-rw-r--r-- | ACE/ChangeLog | 14 | ||||
-rw-r--r-- | ACE/ace/OS_NS_stdlib.cpp | 21 |
2 files changed, 29 insertions, 6 deletions
diff --git a/ACE/ChangeLog b/ACE/ChangeLog index 09ec872a792..3fa20483435 100644 --- a/ACE/ChangeLog +++ b/ACE/ChangeLog @@ -1,3 +1,17 @@ +Sun Mar 18 02:09:31 UTC 2007 Krishnakumar B <kitty@nospam.invalid.domain> + + * ace/OS_NS_stdlib.cpp: Fixed a race condition in + ACE_OS::mkstemp_emulation() where the value from + ACE_OS::gettimeofday() was truncated due to the use of + ACE_Time_Value::msec(void) as opposed to + ACE_Time_Value::msec(ACE_UINT64&) to convert it to milliseconds. + This resulted in seed value passed to ACE_OS::rand_r() returning + the same sequence of numbers when ACE_OS::mkstemp() was called + successively from the same process. As a result, the filenames + returned from ACE_OS::mkstemp() ended up being the same, if the + template passed in was the same between multiple successive + calls to ACE_OS::mkstemp(). + Thu Mar 15 14:44:21 UTC 2007 Carlos O'Ryan <coryan@atdesk.com> * ace/Select_Reactor_Base.cpp: diff --git a/ACE/ace/OS_NS_stdlib.cpp b/ACE/ace/OS_NS_stdlib.cpp index 2964cbbb49c..622c57642b1 100644 --- a/ACE/ace/OS_NS_stdlib.cpp +++ b/ACE/ace/OS_NS_stdlib.cpp @@ -686,13 +686,23 @@ ACE_OS::mkstemp_emulation (ACE_TCHAR * s) static unsigned int const NUM_RETRIES = 50; static unsigned int const NUM_CHARS = 6; // Do not change! + // Use ACE_Time_Value::msec(ACE_UINT64&) as opposed to + // ACE_Time_Value::msec(void) to avoid truncation. + ACE_UINT64 msec; + + // Use a const ACE_Time_Value to resolve ambiguity between + // ACE_Time_Value::msec (long) and ACE_Time_Value::msec(ACE_UINT64&) const. + const ACE_Time_Value now = ACE_OS::gettimeofday(); + now.msec (msec); + + // Add the process and thread ids to ensure uniqueness. + msec += ACE_OS::getpid(); + msec += (size_t) ACE_OS::thr_self(); + // ACE_thread_t may be a char* (returned by ACE_OS::thr_self()) so // we need to use a C-style cast as a catch-all in order to use a // static_cast<> to an integral type. - ACE_RANDR_TYPE seed = - static_cast<ACE_RANDR_TYPE> (ACE_OS::gettimeofday ().msec ()) - + static_cast<ACE_RANDR_TYPE> (ACE_OS::getpid ()) - + static_cast<ACE_RANDR_TYPE> ((size_t)ACE_OS::thr_self ()); + ACE_RANDR_TYPE seed = static_cast<ACE_RANDR_TYPE> (msec); // We only care about UTF-8 / ASCII characters in generated // filenames. A UTF-16 or UTF-32 character could potentially cause @@ -732,8 +742,7 @@ ACE_OS::mkstemp_emulation (ACE_TCHAR * s) // selection to work for EBCDIC, as well. do { - r = - static_cast<ACE_TCHAR> (coefficient * ACE_OS::rand_r (seed)); + r = static_cast<ACE_TCHAR> (coefficient * ACE_OS::rand_r (seed)); } while (!ACE_OS::ace_isalnum (r)); |