File U_os-use-arc4random_buf-if-available-to-generate-cookies.patch of Package xorg-x11-server.24940
Git-commit: 957e8db38f27932d353e86e9aa69cf16778b18f1
Patch-mainline: Upstream
Author: Matthieu Herrb <matthieu@herrb.eu>
Subject: Use arc4random_buf(3) if available to generate cookies.
References: bnc#1025084
Signed-off-by: Michal Srb <msrb@suse.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
Signed-off-by: Matthieu Herrb <matthieu@herrb.eu>
Index: xorg-server-1.18.3/configure.ac
===================================================================
--- xorg-server-1.18.3.orig/configure.ac
+++ xorg-server-1.18.3/configure.ac
@@ -223,6 +223,8 @@ AC_CHECK_FUNCS([backtrace ffs geteuid ge
AC_REPLACE_FUNCS([reallocarray strcasecmp strcasestr strlcat strlcpy strndup\
timingsafe_memcmp])
+AC_CHECK_LIB([bsd], [arc4random_buf])
+
AC_CHECK_DECLS([program_invocation_short_name], [], [], [[#include <errno.h>]])
dnl Check for SO_PEERCRED #define
Index: xorg-server-1.18.3/include/dix-config.h.in
===================================================================
--- xorg-server-1.18.3.orig/include/dix-config.h.in
+++ xorg-server-1.18.3/include/dix-config.h.in
@@ -125,6 +125,9 @@
/* Build a standalone xpbproxy */
#undef STANDALONE_XPBPROXY
+/* Define to 1 if you have the `bsd' library (-lbsd). */
+#undef HAVE_LIBBSD
+
/* Define to 1 if you have the `m' library (-lm). */
#undef HAVE_LIBM
@@ -155,6 +158,9 @@
/* Define to 1 if you have the <rpcsvc/dbm.h> header file. */
#undef HAVE_RPCSVC_DBM_H
+/* Define to 1 if you have the `arc4random_buf' function. */
+#undef HAVE_ARC4RANDOM_BUF
+
/* Define to use libc SHA1 functions */
#undef HAVE_SHA1_IN_LIBC
Index: xorg-server-1.18.3/os/auth.c
===================================================================
--- xorg-server-1.18.3.orig/os/auth.c
+++ xorg-server-1.18.3/os/auth.c
@@ -45,6 +45,9 @@ from The Open Group.
#ifdef WIN32
#include <X11/Xw32defs.h>
#endif
+#ifdef HAVE_LIBBSD
+#include <bsd/stdlib.h> /* for arc4random_buf() */
+#endif
struct protocol {
unsigned short name_length;
@@ -302,11 +305,15 @@ GenerateAuthorization(unsigned name_leng
void
GenerateRandomData(int len, char *buf)
{
+#ifdef HAVE_ARC4RANDOMBUF
+ arc4random_buf(buf, len);
+#else
int fd;
fd = open("/dev/urandom", O_RDONLY);
read(fd, buf, len);
close(fd);
+#endif
}
#endif /* XCSECURITY */