[openssl] master update

dev at ddvo.net dev at ddvo.net
Tue May 18 12:49:56 UTC 2021


The branch master has been updated
       via  9be5f9a8698b0d902ef1281716eda73a4d8478ed (commit)
      from  78c44e4f819721eb80ad95fddc360a34f9e93118 (commit)


- Log -----------------------------------------------------------------
commit 9be5f9a8698b0d902ef1281716eda73a4d8478ed
Author: Dr. David von Oheimb <David.von.Oheimb at siemens.com>
Date:   Mon May 17 13:24:20 2021 +0200

    Move ossl_sleep() to e_os.h and use it in apps
    
    Fixes #15304
    
    Reviewed-by: Tomas Mraz <tomas at openssl.org>
    Reviewed-by: Paul Dale <pauli at openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/15308)

-----------------------------------------------------------------------

Summary of changes:
 apps/cmp.c                  |  2 +-
 apps/lib/http_server.c      |  6 +++---
 apps/s_server.c             |  8 ++------
 crypto/bio/bio_lib.c        |  1 -
 crypto/cmp/cmp_client.c     |  1 +
 e_os.h                      | 48 +++++++++++++++++++++++++++++++++++++++++++++
 include/internal/cryptlib.h | 48 ---------------------------------------------
 test/helpers/ssltestlib.c   |  3 +--
 8 files changed, 56 insertions(+), 61 deletions(-)

diff --git a/apps/cmp.c b/apps/cmp.c
index 70ca9a34fd..f289943a55 100644
--- a/apps/cmp.c
+++ b/apps/cmp.c
@@ -2705,7 +2705,7 @@ int cmp_main(int argc, char **argv)
                                            prog, opt_port, 0, 0);
             if (ret == 0) { /* no request yet */
                 if (retry) {
-                    sleep(1);
+                    ossl_sleep(1000);
                     retry = 0;
                     continue;
                 }
diff --git a/apps/lib/http_server.c b/apps/lib/http_server.c
index e7e84fa4c5..b39f218507 100644
--- a/apps/lib/http_server.c
+++ b/apps/lib/http_server.c
@@ -96,7 +96,7 @@ static void killall(int ret, pid_t *kidpids)
         if (kidpids[i] != 0)
             (void)kill(kidpids[i], SIGTERM);
     OPENSSL_free(kidpids);
-    sleep(1);
+    ossl_sleep(1000);
     exit(ret);
 }
 
@@ -166,7 +166,7 @@ void spawn_loop(const char *prog)
                                WCOREDUMP(status) ? " (core dumped)" :
 # endif
                                "");
-                    sleep(1);
+                    ossl_sleep(1000);
                 }
                 break;
             } else if (errno != EINTR) {
@@ -180,7 +180,7 @@ void spawn_loop(const char *prog)
         switch (fpid = fork()) {
         case -1: /* error */
             /* System critically low on memory, pause and try again later */
-            sleep(30);
+            ossl_sleep(30000);
             break;
         case 0: /* child */
             OPENSSL_free(kidpids);
diff --git a/apps/s_server.c b/apps/s_server.c
index 80c8a08c01..292ffbe762 100644
--- a/apps/s_server.c
+++ b/apps/s_server.c
@@ -3057,9 +3057,7 @@ static int www_body(int s, int stype, int prot, unsigned char *context)
                     continue;
                 }
 #endif
-#if !defined(OPENSSL_SYS_MSDOS)
-                sleep(1);
-#endif
+                ossl_sleep(1000);
                 continue;
             }
         } else if (i == 0) {    /* end of input */
@@ -3486,9 +3484,7 @@ static int rev_body(int s, int stype, int prot, unsigned char *context)
                     continue;
                 }
 #endif
-#if !defined(OPENSSL_SYS_MSDOS)
-                sleep(1);
-#endif
+                ossl_sleep(1000);
                 continue;
             }
         } else if (i == 0) {    /* end of input */
diff --git a/crypto/bio/bio_lib.c b/crypto/bio/bio_lib.c
index 575107634c..3fa8ff4f16 100644
--- a/crypto/bio/bio_lib.c
+++ b/crypto/bio/bio_lib.c
@@ -11,7 +11,6 @@
 #include <errno.h>
 #include <openssl/crypto.h>
 #include "bio_local.h"
-#include "internal/cryptlib.h"
 
 /*
  * Helper macro for the callback to determine whether an operator expects a
diff --git a/crypto/cmp/cmp_client.c b/crypto/cmp/cmp_client.c
index 54c8f5094b..dce7d0c010 100644
--- a/crypto/cmp/cmp_client.c
+++ b/crypto/cmp/cmp_client.c
@@ -11,6 +11,7 @@
 
 #include "cmp_local.h"
 #include "internal/cryptlib.h"
+#include "e_os.h" /* ossl_sleep() */
 
 /* explicit #includes not strictly needed since implied by the above: */
 #include <openssl/bio.h>
diff --git a/e_os.h b/e_os.h
index 8bfc1dcb10..56ea62d06f 100644
--- a/e_os.h
+++ b/e_os.h
@@ -303,6 +303,54 @@ struct servent *getservbyname(const char *name, const char *proto);
 # endif
 /* end vxworks */
 
+/* system-specific variants defining ossl_sleep() */
+#ifdef OPENSSL_SYS_UNIX
+# include <unistd.h>
+static ossl_inline void ossl_sleep(unsigned long millis)
+{
+# ifdef OPENSSL_SYS_VXWORKS
+    struct timespec ts;
+    ts.tv_sec = (long int) (millis / 1000);
+    ts.tv_nsec = (long int) (millis % 1000) * 1000000ul;
+    nanosleep(&ts, NULL);
+# elif defined(__TANDEM)
+#  if !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);
+# endif
+}
+#elif defined(_WIN32)
+# include <windows.h>
+static ossl_inline void ossl_sleep(unsigned long millis)
+{
+    Sleep(millis);
+}
+#else
+/* Fallback to a busy wait */
+static ossl_inline void ossl_sleep(unsigned long millis)
+{
+    struct timeval start, now;
+    unsigned long elapsedms;
+
+    gettimeofday(&start, NULL);
+    do {
+        gettimeofday(&now, NULL);
+        elapsedms = (((now.tv_sec - start.tv_sec) * 1000000)
+                     + now.tv_usec - start.tv_usec) / 1000;
+    } while (elapsedms < millis);
+}
+#endif /* defined OPENSSL_SYS_UNIX */
+
 /* ----------------------------- HP NonStop -------------------------------- */
 /* Required to support platform variant without getpid() and pid_t. */
 # if defined(__TANDEM) && defined(_GUARDIAN_TARGET)
diff --git a/include/internal/cryptlib.h b/include/internal/cryptlib.h
index 966c8f26f1..3499025fa1 100644
--- a/include/internal/cryptlib.h
+++ b/include/internal/cryptlib.h
@@ -218,54 +218,6 @@ const void *ossl_bsearch(const void *key, const void *base, int num,
                          int size, int (*cmp) (const void *, const void *),
                          int flags);
 
-/* system-specific variants defining ossl_sleep() */
-#ifdef OPENSSL_SYS_UNIX
-# include <unistd.h>
-static ossl_inline void ossl_sleep(unsigned long millis)
-{
-# ifdef OPENSSL_SYS_VXWORKS
-    struct timespec ts;
-    ts.tv_sec = (long int) (millis / 1000);
-    ts.tv_nsec = (long int) (millis % 1000) * 1000000ul;
-    nanosleep(&ts, NULL);
-# elif defined(__TANDEM)
-#  if !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);
-# endif
-}
-#elif defined(_WIN32)
-# include <windows.h>
-static ossl_inline void ossl_sleep(unsigned long millis)
-{
-    Sleep(millis);
-}
-#else
-/* Fallback to a busy wait */
-static ossl_inline void ossl_sleep(unsigned long millis)
-{
-    struct timeval start, now;
-    unsigned long elapsedms;
-
-    gettimeofday(&start, NULL);
-    do {
-        gettimeofday(&now, NULL);
-        elapsedms = (((now.tv_sec - start.tv_sec) * 1000000)
-                     + now.tv_usec - start.tv_usec) / 1000;
-    } while (elapsedms < millis);
-}
-#endif /* defined OPENSSL_SYS_UNIX */
-
 char *ossl_sk_ASN1_UTF8STRING2text(STACK_OF(ASN1_UTF8STRING) *text,
                                    const char *sep, size_t max_len);
 char *ossl_ipaddr_to_asc(unsigned char *p, int len);
diff --git a/test/helpers/ssltestlib.c b/test/helpers/ssltestlib.c
index daa0416be6..52b1799b68 100644
--- a/test/helpers/ssltestlib.c
+++ b/test/helpers/ssltestlib.c
@@ -10,10 +10,9 @@
 #include <string.h>
 
 #include "internal/nelem.h"
-#include "internal/cryptlib.h" /* for ossl_sleep() */
 #include "ssltestlib.h"
 #include "../testutil.h"
-#include "e_os.h"
+#include "e_os.h" /* for ossl_sleep() etc. */
 
 #ifdef OPENSSL_SYS_UNIX
 # include <unistd.h>


More information about the openssl-commits mailing list