[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
feature/native-comp 98196b0 4/4: Merge remote-tracking branch 'savannah/
From: |
Andrea Corallo |
Subject: |
feature/native-comp 98196b0 4/4: Merge remote-tracking branch 'savannah/master' into uninterned |
Date: |
Sun, 28 Jun 2020 10:55:33 -0400 (EDT) |
branch: feature/native-comp
commit 98196b03c170a148bb5d558bb9df8a923a652ed6
Merge: 6c7f615a e4028d1
Author: Andrea Corallo <akrl@sdf.org>
Commit: Andrea Corallo <akrl@sdf.org>
Merge remote-tracking branch 'savannah/master' into uninterned
---
admin/merge-gnulib | 2 +-
configure.ac | 3 ++-
doc/lispref/text.texi | 8 +++-----
src/fns.c | 15 ++++++++++-----
src/sysdep.c | 32 ++++++--------------------------
src/systhread.c | 8 ++++++++
6 files changed, 30 insertions(+), 38 deletions(-)
diff --git a/admin/merge-gnulib b/admin/merge-gnulib
index 99469e4..5a78b05 100755
--- a/admin/merge-gnulib
+++ b/admin/merge-gnulib
@@ -35,7 +35,7 @@ GNULIB_MODULES='
environ execinfo explicit_bzero faccessat
fchmodat fcntl fcntl-h fdopendir
filemode filename filevercmp flexmember fpieee fstatat fsusage fsync futimens
- getloadavg getopt-gnu gettime gettimeofday gitlog-to-changelog
+ getloadavg getopt-gnu getrandom gettime gettimeofday gitlog-to-changelog
ieee754-h ignore-value intprops largefile lstat
manywarnings memmem-simple mempcpy memrchr minmax mkostemp mktime nstrftime
pathmax pipe2 pselect pthread_sigmask
diff --git a/configure.ac b/configure.ac
index aa42c8b..7b72ec0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -4275,7 +4275,8 @@ pthread_sigmask strsignal setitimer timer_getoverrun \
sendto recvfrom getsockname getifaddrs freeifaddrs \
gai_strerror sync \
getpwent endpwent getgrent endgrent \
-cfmakeraw cfsetspeed __executable_start log2 pthread_setname_np)
+cfmakeraw cfsetspeed __executable_start log2 pthread_setname_np \
+pthread_set_name_np)
LIBS=$OLD_LIBS
if test "$ac_cv_func_pthread_setname_np" = "yes"; then
diff --git a/doc/lispref/text.texi b/doc/lispref/text.texi
index 10e8246..0c3813f 100644
--- a/doc/lispref/text.texi
+++ b/doc/lispref/text.texi
@@ -4813,11 +4813,9 @@ When @var{noerror} is non-@code{nil}, this function
silently uses
@code{raw-text} coding instead.
@item (@code{iv-auto} @var{length})
-This will generate an IV (Initialization Vector) of the specified
-length using the GnuTLS @code{GNUTLS_RND_NONCE} generator and pass it
-to the function. This ensures that the IV is unpredictable and
-unlikely to be reused in the same session. The actual value of the IV
-is returned by the function as described below.
+This generates a random IV (Initialization Vector) of the specified
+length and passes it to the function. This ensures that the IV is
+unpredictable and unlikely to be reused in the same session.
@end table
diff --git a/src/fns.c b/src/fns.c
index b2f84b2..c1465f7 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -21,6 +21,7 @@ along with GNU Emacs. If not, see
<https://www.gnu.org/licenses/>. */
#include <config.h>
#include <stdlib.h>
+#include <sys/random.h>
#include <unistd.h>
#include <filevercmp.h>
#include <intprops.h>
@@ -5267,7 +5268,6 @@ extract_data_from_object (Lisp_Object spec,
}
else if (EQ (object, Qiv_auto))
{
-#ifdef HAVE_GNUTLS3
/* Format: (iv-auto REQUIRED-LENGTH). */
if (! FIXNATP (start))
@@ -5276,14 +5276,19 @@ extract_data_from_object (Lisp_Object spec,
{
EMACS_INT start_hold = XFIXNAT (start);
object = make_uninit_string (start_hold);
- gnutls_rnd (GNUTLS_RND_NONCE, SSDATA (object), start_hold);
+ char *lim = SSDATA (object) + start_hold;
+ for (char *p = SSDATA (object); p < lim; p++)
+ {
+ ssize_t gotten = getrandom (p, lim - p, 0);
+ if (0 <= gotten)
+ p += gotten;
+ else if (errno != EINTR)
+ report_file_error ("Getting random data", Qnil);
+ }
*start_byte = 0;
*end_byte = start_hold;
}
-#else
- error ("GnuTLS is not available, so `iv-auto' can't be used");
-#endif
}
if (!STRINGP (object))
diff --git a/src/sysdep.c b/src/sysdep.c
index cbd306a..6b54ed3 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -27,6 +27,7 @@ along with GNU Emacs. If not, see
<https://www.gnu.org/licenses/>. */
#endif /* HAVE_PWD_H */
#include <limits.h>
#include <stdlib.h>
+#include <sys/random.h>
#include <unistd.h>
#include <c-ctype.h>
@@ -115,16 +116,6 @@ along with GNU Emacs. If not, see
<https://www.gnu.org/licenses/>. */
#include "process.h"
#include "cm.h"
-#include "gnutls.h"
-/* MS-Windows loads GnuTLS at run time, if available; we don't want to
- do that during startup just to call gnutls_rnd. */
-#if defined HAVE_GNUTLS && !defined WINDOWSNT
-# include <gnutls/crypto.h>
-#else
-# define emacs_gnutls_global_init() Qnil
-# define gnutls_rnd(level, data, len) (-1)
-#endif
-
#ifdef WINDOWSNT
# include <direct.h>
/* In process.h which conflicts with the local copy. */
@@ -2278,9 +2269,7 @@ init_signals (void)
typedef unsigned int random_seed;
static void set_random_seed (random_seed arg) { srandom (arg); }
#elif defined HAVE_LRAND48
-/* Although srand48 uses a long seed, this is unsigned long to avoid
- undefined behavior on signed integer overflow in init_random. */
-typedef unsigned long int random_seed;
+typedef long int random_seed;
static void set_random_seed (random_seed arg) { srand48 (arg); }
#else
typedef unsigned int random_seed;
@@ -2307,23 +2296,14 @@ init_random (void)
/* First, try seeding the PRNG from the operating system's entropy
source. This approach is both fast and secure. */
#ifdef WINDOWSNT
+ /* FIXME: Perhaps getrandom can be used here too? */
success = w32_init_random (&v, sizeof v) == 0;
#else
- int fd = emacs_open ("/dev/urandom", O_RDONLY, 0);
- if (0 <= fd)
- {
- success = emacs_read (fd, &v, sizeof v) == sizeof v;
- close (fd);
- }
+ verify (sizeof v <= 256);
+ success = getrandom (&v, sizeof v, 0) == sizeof v;
#endif
- /* If that didn't work, try using GnuTLS, which is secure, but on
- some systems, can be somewhat slow. */
- if (!success)
- success = EQ (emacs_gnutls_global_init (), Qt)
- && gnutls_rnd (GNUTLS_RND_NONCE, &v, sizeof v) == 0;
-
- /* If _that_ didn't work, just use the current time value and PID.
+ /* If that didn't work, just use the current time value and PID.
It's at least better than XKCD 221. */
if (!success)
{
diff --git a/src/systhread.c b/src/systhread.c
index 0d600d6..ebd7552 100644
--- a/src/systhread.c
+++ b/src/systhread.c
@@ -26,6 +26,10 @@ along with GNU Emacs. If not, see
<https://www.gnu.org/licenses/>. */
#include "nsterm.h"
#endif
+#ifdef HAVE_PTHREAD_SET_NAME_NP
+#include <pthread_np.h>
+#endif
+
#ifndef THREADS_ENABLED
void
@@ -221,6 +225,10 @@ sys_thread_set_name (const char *name)
# else
pthread_setname_np (pthread_self (), p_name);
# endif
+#elif HAVE_PTHREAD_SET_NAME_NP
+ /* The name will automatically be truncated if it exceeds a
+ system-specific length. */
+ pthread_set_name_np (pthread_self (), name);
#endif
}