summaryrefslogtreecommitdiffstats
path: root/contrib/unbound/compat
diff options
context:
space:
mode:
authordes <des@FreeBSD.org>2015-09-17 16:10:11 +0000
committerdes <des@FreeBSD.org>2015-09-17 16:10:11 +0000
commitc5050a3b9f622f6308084b1e253919467f3c6ff0 (patch)
tree9ba31f6272e0b39184eba0b36bb65cda61f09b93 /contrib/unbound/compat
parent5ef9f703be928fbaab82c07bd99fa37838acd02f (diff)
parent0b3e2c01ad6e393f14541f9b977e89fdb993a100 (diff)
downloadFreeBSD-src-c5050a3b9f622f6308084b1e253919467f3c6ff0.zip
FreeBSD-src-c5050a3b9f622f6308084b1e253919467f3c6ff0.tar.gz
Upgrade to Unbound 1.5.4.
Diffstat (limited to 'contrib/unbound/compat')
-rw-r--r--contrib/unbound/compat/getentropy_linux.c34
-rw-r--r--contrib/unbound/compat/reallocarray.c39
2 files changed, 69 insertions, 4 deletions
diff --git a/contrib/unbound/compat/getentropy_linux.c b/contrib/unbound/compat/getentropy_linux.c
index d4adab2..76f0f9d 100644
--- a/contrib/unbound/compat/getentropy_linux.c
+++ b/contrib/unbound/compat/getentropy_linux.c
@@ -77,6 +77,9 @@ int getentropy(void *buf, size_t len);
extern int main(int, char *argv[]);
#endif
static int gotdata(char *buf, size_t len);
+#ifdef SYS_getrandom
+static int getentropy_getrandom(void *buf, size_t len);
+#endif
static int getentropy_urandom(void *buf, size_t len);
#ifdef SYS__sysctl
static int getentropy_sysctl(void *buf, size_t len);
@@ -94,11 +97,15 @@ getentropy(void *buf, size_t len)
}
#ifdef SYS_getrandom
- /* try to use getrandom syscall introduced with kernel 3.17 */
- ret = syscall(SYS_getrandom, buf, len, 0);
+ /*
+ * Try descriptor-less getrandom()
+ */
+ ret = getentropy_getrandom(buf, len);
if (ret != -1)
return (ret);
-#endif /* SYS_getrandom */
+ if (errno != ENOSYS)
+ return (-1);
+#endif
/*
* Try to get entropy with /dev/urandom
@@ -185,6 +192,25 @@ gotdata(char *buf, size_t len)
return 0;
}
+#ifdef SYS_getrandom
+static int
+getentropy_getrandom(void *buf, size_t len)
+{
+ int pre_errno = errno;
+ int ret;
+ if (len > 256)
+ return (-1);
+ do {
+ ret = syscall(SYS_getrandom, buf, len, 0);
+ } while (ret == -1 && errno == EINTR);
+
+ if (ret != (int)len)
+ return (-1);
+ errno = pre_errno;
+ return (0);
+}
+#endif
+
static int
getentropy_urandom(void *buf, size_t len)
{
@@ -258,7 +284,7 @@ getentropy_sysctl(void *buf, size_t len)
struct __sysctl_args args = {
.name = mib,
.nlen = 3,
- .oldval = buf + i,
+ .oldval = (char *)buf + i,
.oldlenp = &chunk,
};
if (syscall(SYS__sysctl, &args) != 0)
diff --git a/contrib/unbound/compat/reallocarray.c b/contrib/unbound/compat/reallocarray.c
new file mode 100644
index 0000000..04d5d71
--- /dev/null
+++ b/contrib/unbound/compat/reallocarray.c
@@ -0,0 +1,39 @@
+/* $OpenBSD: reallocarray.c,v 1.1 2014/05/08 21:43:49 deraadt Exp $ */
+/*
+ * Copyright (c) 2008 Otto Moerbeek <otto@drijf.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * 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.
+ */
+
+#include "config.h"
+#include <sys/types.h>
+#include <errno.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+/*
+ * This is sqrt(SIZE_MAX+1), as s1*s2 <= SIZE_MAX
+ * if both s1 < MUL_NO_OVERFLOW and s2 < MUL_NO_OVERFLOW
+ */
+#define MUL_NO_OVERFLOW ((size_t)1 << (sizeof(size_t) * 4))
+
+void *
+reallocarray(void *optr, size_t nmemb, size_t size)
+{
+ if ((nmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) &&
+ nmemb > 0 && SIZE_MAX / nmemb < size) {
+ errno = ENOMEM;
+ return NULL;
+ }
+ return realloc(optr, size * nmemb);
+}
OpenPOWER on IntegriCloud