]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
- Downgrade compat/getentropy_solaris.c to version 1.4 from OpenBSD.
authorGeorge Thessalonikefs <george@nlnetlabs.nl>
Tue, 7 Jan 2020 13:06:14 +0000 (15:06 +0200)
committerGeorge Thessalonikefs <george@nlnetlabs.nl>
Tue, 7 Jan 2020 13:06:14 +0000 (15:06 +0200)
  The dl_iterate_phdr() function introduced in newer versions raises
  compilation errors on solaris 10.

compat/getentropy_solaris.c
doc/Changelog

index 0a03046d468144c55fbd99b36ba4081e8b8bf758..cfd5b70475e31cdf89853520c2dcbdde40903b3a 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: getentropy_solaris.c,v 1.13 2018/11/20 08:04:28 deraadt Exp $ */
+/*     $OpenBSD: getentropy_solaris.c,v 1.4 2014/07/12 20:41:47 wouter Exp $   */
 
 /*
  * Copyright (c) 2014 Theo de Raadt <deraadt@openbsd.org>
  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- *
- * Emulation of getentropy(2) as documented at:
- * http://man.openbsd.org/getentropy.2
  */
 
-#include "config.h"
 #include <sys/types.h>
 #include <sys/param.h>
 #include <sys/ioctl.h>
 #include <sys/stat.h>
 #include <sys/time.h>
 #include <stdlib.h>
-#ifdef HAVE_STDINT_H
 #include <stdint.h>
-#endif
 #include <stdio.h>
-#include <link.h>
 #include <termios.h>
 #include <fcntl.h>
 #include <signal.h>
 #include <errno.h>
 #include <unistd.h>
 #include <time.h>
-#ifdef HAVE_SYS_SHA2_H
 #include <sys/sha2.h>
 #define SHA512_Init SHA512Init
 #define SHA512_Update SHA512Update
 #define SHA512_Final SHA512Final
-#else
-#include "openssl/sha.h"
-#endif
 
 #include <sys/vfs.h>
 #include <sys/statfs.h>
 
 #define HR(x, l) (SHA512_Update(&ctx, (char *)(x), (l)))
 #define HD(x)   (SHA512_Update(&ctx, (char *)&(x), sizeof (x)))
-#define HF(x)    (SHA512_Update(&ctx, (char *)&(x), sizeof (void*)))
+#define HF(x)   (SHA512_Update(&ctx, (char *)&(x), sizeof (void*)))
 
 int    getentropy(void *buf, size_t len);
 
+extern int main(int, char *argv[]);
+static int gotdata(char *buf, size_t len);
 static int getentropy_urandom(void *buf, size_t len, const char *path,
     int devfscheck);
 static int getentropy_fallback(void *buf, size_t len);
-static int getentropy_phdr(struct dl_phdr_info *info, size_t size, void *data);
 
 int
 getentropy(void *buf, size_t len)
@@ -87,7 +77,7 @@ getentropy(void *buf, size_t len)
 
        if (len > 256) {
                errno = EIO;
-               return (-1);
+               return -1;
        }
 
        /*
@@ -154,6 +144,22 @@ getentropy(void *buf, size_t len)
        return (ret);
 }
 
+/*
+ * Basic sanity checking; wish we could do better.
+ */
+static int
+gotdata(char *buf, size_t len)
+{
+       char    any_set = 0;
+       size_t  i;
+
+       for (i = 0; i < len; ++i)
+               any_set |= buf[i];
+       if (any_set == 0)
+               return -1;
+       return 0;
+}
+
 static int
 getentropy_urandom(void *buf, size_t len, const char *path, int devfscheck)
 {
@@ -200,11 +206,13 @@ start:
                i += ret;
        }
        close(fd);
-       errno = save_errno;
-       return (0);             /* satisfied */
+       if (gotdata(buf, len) == 0) {
+               errno = save_errno;
+               return 0;               /* satisfied */
+       }
 nodevrandom:
        errno = EIO;
-       return (-1);
+       return -1;
 }
 
 static const int cl[] = {
@@ -232,15 +240,6 @@ static const int cl[] = {
 #endif
 };
 
-static int
-getentropy_phdr(struct dl_phdr_info *info, size_t size, void *data)
-{
-       SHA512_CTX *ctx = data;
-
-       SHA512_Update(ctx, &info->dlpi_addr, sizeof (info->dlpi_addr));
-       return (0);
-}
-
 static int
 getentropy_fallback(void *buf, size_t len)
 {
@@ -278,8 +277,6 @@ getentropy_fallback(void *buf, size_t len)
                                cnt += (int)tv.tv_usec;
                        }
 
-                       dl_iterate_phdr(getentropy_phdr, &ctx);
-
                        for (ii = 0; ii < sizeof(cl)/sizeof(cl[0]); ii++)
                                HX(clock_gettime(cl[ii], &ts) == -1, ts);
 
@@ -300,6 +297,7 @@ getentropy_fallback(void *buf, size_t len)
                        HX(sigprocmask(SIG_BLOCK, NULL, &sigset) == -1,
                            sigset);
 
+                       HF(main);               /* an addr in program */
                        HF(getentropy); /* an addr in this library */
                        HF(printf);             /* an addr in libc */
                        p = (char *)&p;
@@ -422,8 +420,11 @@ getentropy_fallback(void *buf, size_t len)
                memcpy((char *)buf + i, results, min(sizeof(results), len - i));
                i += min(sizeof(results), len - i);
        }
-       explicit_bzero(&ctx, sizeof ctx);
-       explicit_bzero(results, sizeof results);
-       errno = save_errno;
-       return (0);             /* satisfied */
+       memset(results, 0, sizeof results);
+       if (gotdata(buf, len) == 0) {
+               errno = save_errno;
+               return 0;               /* satisfied */
+       }
+       errno = EIO;
+       return -1;
 }
index 17b12330a832093e0dae7304b20f5ac060528d1a..6626bcc0c13b00c4d4d91b31fbcc70b1b4b64b3b 100644 (file)
@@ -1,3 +1,8 @@
+6 January 2020: George
+       - Downgrade compat/getentropy_solaris.c to version 1.4 from OpenBSD.
+         The dl_iterate_phdr() function introduced in newer versions raises
+         compilation errors on solaris 10.
+
 6 January 2020: Wouter
        - Merge #135 from Florian Obser: Use passed in neg and key cache
          if non-NULL.