Commit ff75605a authored by Natanael Copa's avatar Natanael Copa
Browse files

main/dbus: update getrandom patch

update getrandom patch after feedback from upstream
ref #11327
parent 1df774ab
From 48bc80fcb26f3e15d23766e100a3e2488c49f9ec Mon Sep 17 00:00:00 2001
From 7faabbeb1d735069a2fd1e24e20b2543306a0e28 Mon Sep 17 00:00:00 2001
From: Natanael Copa <ncopa@alpinelinux.org>
Date: Tue, 24 Mar 2020 11:31:41 +0100
Subject: [PATCH] _dbus_generate_random_bytes: fallback to getrandom(2)
Subject: [PATCH] _dbus_generate_random_bytes: use getrandom(2)
Fall back to getrandom(2) in case /dev/urandom is missing. This may for
example happen if dbus-uuidgen is called in a chroot or at early boot.
Use getrandom(2) and fall back to /dev/urandom if it is missing or if it
fails some any reason.
This solves problem where dbus-uuidgen is called from a chroot which
lacks /dev/urandom.
Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
---
cmake/ConfigureChecks.cmake | 2 ++
cmake/config.h.cmake | 2 ++
configure.ac | 3 ++-
dbus/dbus-sysdeps-unix.c | 17 +++++++++++++++++
4 files changed, 23 insertions(+), 1 deletion(-)
dbus/dbus-sysdeps-unix.c | 23 ++++++++++++++++++++---
4 files changed, 26 insertions(+), 4 deletions(-)
diff --git a/cmake/ConfigureChecks.cmake b/cmake/ConfigureChecks.cmake
index a9a5fc90..f920c75f 100644
......@@ -76,7 +79,7 @@ index a1ba877a..c9f50b0f 100644
AC_CHECK_HEADERS(dirent.h)
diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c
index e8cd5b33..fc9facc3 100644
index e8cd5b33..44f7711e 100644
--- a/dbus/dbus-sysdeps-unix.c
+++ b/dbus/dbus-sysdeps-unix.c
@@ -80,6 +80,9 @@
......@@ -89,30 +92,36 @@ index e8cd5b33..fc9facc3 100644
#ifdef HAVE_ADT
#include <bsm/adt.h>
@@ -3170,9 +3173,23 @@ _dbus_generate_random_bytes (DBusString *str,
if (fd < 0)
{
@@ -3158,12 +3161,26 @@ _dbus_generate_random_bytes (DBusString *str,
int n_bytes,
DBusError *error)
{
- int old_len;
+ int old_len = _dbus_string_get_length (str);
int fd;
int result;
+#ifdef HAVE_GETRANDOM
+ result = getrandom (str, n_bytes, GRND_NONBLOCK);
+ if (result == n_bytes)
+ return TRUE;
+ char *buffer;
+
+ if (!_dbus_string_lengthen (str, n_bytes))
+ {
+ _DBUS_SET_OOM (error);
+ return FALSE;
+ }
+
+ buffer = _dbus_string_get_data_len (str, old_len, n_bytes);
+ result = getrandom (buffer, n_bytes, GRND_NONBLOCK);
- old_len = _dbus_string_get_length (str);
- fd = -1;
+ if (result == n_bytes)
+ return TRUE;
+
+ if (result < 0)
+ dbus_set_error (error, _dbus_error_from_errno (errno),
+ "Could not read from getrandom(): %s",
+ _dbus_strerror (errno));
+ else
+ dbus_set_error (error, DBUS_ERROR_IO_ERROR,
+ "Short read from getrandom()");
+#else
dbus_set_error (error, _dbus_error_from_errno (errno),
"Could not open /dev/urandom: %s",
_dbus_strerror (errno));
+ _dbus_string_set_length (str, old_len);
+#endif
return FALSE;
}
/* note, urandom on linux will fall back to pseudorandom */
fd = open ("/dev/urandom", O_RDONLY);
--
2.25.2
2.26.0
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=dbus
pkgver=1.12.16
pkgrel=3
pkgrel=4
pkgdesc="Freedesktop.org message bus system"
options="!check" # Introduces circular dependency with xorg-server (xvfb-run -> xvfb)
url="https://www.freedesktop.org/Software/dbus"
......@@ -22,7 +22,7 @@ makedepends="$depends_dev
checkdepends="xvfb-run"
install="$pkgname.pre-install $pkgname.post-install"
source="https://dbus.freedesktop.org/releases/dbus/dbus-$pkgver.tar.gz
0001-_dbus_generate_random_bytes-fallback-to-getrandom-2.patch
0001-_dbus_generate_random_bytes-use-getrandom-2.patch
$pkgname.initd
"
......@@ -86,5 +86,5 @@ x11() {
}
sha512sums="27ae805170e9515a8bb0fba5f29d414edc70e3b6b28b7b65bbea47035b8eafa9ac4820cdc92645be6035f6748f8aa45679e1ffc84ba74a64859a3056d318b9bb dbus-1.12.16.tar.gz
10f074b88bcd0aaec2edba6ce346a6f52daf7cc79646e0ab86982325d137eefc0e1cb1f58a500d681a1a40348957bbc5cea358aeb55d248ec90d77a224d5f5cd 0001-_dbus_generate_random_bytes-fallback-to-getrandom-2.patch
3db35499361e84d8e2469b88b033f49813b179188ac25f1841a989988c352af398a56dfd94383813626c6dfd032194f7a9fcdba001ccc3e005e7cd22dae7a7ed 0001-_dbus_generate_random_bytes-use-getrandom-2.patch
4c6beba2382416e60a3adfa85ef843d90d93ca5f38c23f573e058ffca6d4fc3850d11d40938c74383bba61599569b7fdfb1fcf3b9d2f1463e6b2e2cc81097c84 dbus.initd"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment