]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Correct ossl_sleep for threaded model by introducing sleep().
authorRandall S. Becker <randall.becker@nexbridge.ca>
Mon, 25 Mar 2024 19:30:53 +0000 (19:30 +0000)
committerTomas Mraz <tomas@openssl.org>
Mon, 6 May 2024 08:50:43 +0000 (10:50 +0200)
This fix handles situations where ossl_sleep() receives a millis value equal
or greater than 1000, which breaks platforms where this is not legal. The
change also avoids unnecessarily calling sleep(0).

Fixes: #23961
Signed-off-by: Randall S. Becker <randall.becker@nexbridge.ca>
Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/23972)

(cherry picked from commit c263b1fd692bd610b1a3879a9cdad74f3ffe321d)

include/internal/e_os.h

index 7fdc3899823cb43127d3b85bd19a28a3d3e933ea..c7802d6e6cf732d6371b7b74f42ddafdbcc20bbe 100644 (file)
@@ -296,20 +296,18 @@ static ossl_inline void ossl_sleep(unsigned long millis)
     ts.tv_sec = (long int) (millis / 1000);
     ts.tv_nsec = (long int) (millis % 1000) * 1000000ul;
     nanosleep(&ts, NULL);
-# elif defined(__TANDEM)
-#  if !defined(_REENTRANT)
+# elif defined(__TANDEM) && !defined(_REENTRANT)
 #   include <cextdecs.h(PROCESS_DELAY_)>
+
     /* HPNS does not support usleep for non threaded apps */
     PROCESS_DELAY_(millis * 1000);
-#  elif defined(_SPT_MODEL_)
-#   include <spthread.h>
-#   include <spt_extensions.h>
-    usleep(millis * 1000);
-#  else
-    usleep(millis * 1000);
-#  endif
 # else
-    usleep(millis * 1000);
+    unsigned int s = (unsigned int)(millis / 1000);
+    unsigned int us = (unsigned int)((millis % 1000) * 1000);
+
+    if (s > 0)
+        sleep(s);
+    usleep(us);
 # endif
 }
 #elif defined(_WIN32)