churchyard / rpms / python3

Forked from rpms/python3 3 years ago
Clone

Blame 00187-remove-pthread-atfork.patch

f5250e
diff -r 6fdbb81b4020 -r 705f2addd0f0 Modules/_ssl.c
f5250e
--- a/Modules/_ssl.c	Tue Oct 29 12:14:55 2013 +0100
f5250e
+++ b/Modules/_ssl.c	Tue Oct 29 21:11:55 2013 +0100
f5250e
@@ -19,9 +19,6 @@
f5250e
 #ifdef WITH_THREAD
f5250e
 #include "pythread.h"
f5250e
 
f5250e
-#ifdef HAVE_PTHREAD_ATFORK
f5250e
-#  include <pthread.h>
f5250e
-#endif
f5250e
 
f5250e
 #define PySSL_BEGIN_ALLOW_THREADS_S(save) \
f5250e
     do { if (_ssl_locks_count>0) { (save) = PyEval_SaveThread(); } } while (0)
f5250e
@@ -2950,64 +2947,6 @@
f5250e
 Returns number of bytes read.  Raises SSLError if connection to EGD\n\
f5250e
 fails or if it does not provide enough data to seed PRNG.");
f5250e
 
f5250e
-/* Seed OpenSSL's PRNG at fork(), http://bugs.python.org/issue18747
f5250e
- *
f5250e
- * The parent handler seeds the PRNG from pseudo-random data like pid, the
f5250e
- * current time (miliseconds or seconds) and an uninitialized array.
f5250e
- * The array contains stack variables that are impossible to predict
f5250e
- * on most systems, e.g. function return address (subject to ASLR), the
f5250e
- * stack protection canary and automatic variables.
f5250e
- * The code is inspired by Apache's ssl_rand_seed() function.
f5250e
- *
f5250e
- * Note:
f5250e
- * The code uses pthread_atfork() until Python has a proper atfork API. The
f5250e
- * handlers are not removed from the child process. A parent handler is used
f5250e
- * instead of a child handler because fork() is supposed to be async-signal
f5250e
- * safe but the handler calls unsafe functions.
f5250e
- */
f5250e
-
f5250e
-#if defined(HAVE_PTHREAD_ATFORK) && defined(WITH_THREAD)
f5250e
-#define PYSSL_RAND_ATFORK 1
f5250e
-
f5250e
-static void
f5250e
-PySSL_RAND_atfork_parent(void)
f5250e
-{
f5250e
-    struct {
f5250e
-        char stack[128];    /* uninitialized (!) stack data, 128 is an
f5250e
-                               arbitrary number. */
f5250e
-        pid_t pid;          /* current pid */
f5250e
-        _PyTime_timeval tp; /* current time */
f5250e
-    } seed;
f5250e
-
f5250e
-#ifdef WITH_VALGRIND
f5250e
-    VALGRIND_MAKE_MEM_DEFINED(seed.stack, sizeof(seed.stack));
f5250e
-#endif
f5250e
-    seed.pid = getpid();
f5250e
-    _PyTime_gettimeofday(&(seed.tp));
f5250e
-    RAND_add((unsigned char *)&seed, sizeof(seed), 0.0);
f5250e
-}
f5250e
-
f5250e
-static int
f5250e
-PySSL_RAND_atfork(void)
f5250e
-{
f5250e
-    static int registered = 0;
f5250e
-    int retval;
f5250e
-
f5250e
-    if (registered)
f5250e
-        return 0;
f5250e
-
f5250e
-    retval = pthread_atfork(NULL,                     /* prepare */
f5250e
-                            PySSL_RAND_atfork_parent, /* parent */
f5250e
-                            NULL);                    /* child */
f5250e
-    if (retval != 0) {
f5250e
-        PyErr_SetFromErrno(PyExc_OSError);
f5250e
-        return -1;
f5250e
-    }
f5250e
-    registered = 1;
f5250e
-    return 0;
f5250e
-}
f5250e
-#endif /* HAVE_PTHREAD_ATFORK */
f5250e
-
f5250e
 #endif /* HAVE_OPENSSL_RAND */
f5250e
 
f5250e
 
f5250e
@@ -3623,10 +3561,5 @@
f5250e
     if (r == NULL || PyModule_AddObject(m, "_OPENSSL_API_VERSION", r))
f5250e
         return NULL;
f5250e
 
f5250e
-#ifdef PYSSL_RAND_ATFORK
f5250e
-    if (PySSL_RAND_atfork() == -1)
f5250e
-        return NULL;
f5250e
-#endif
f5250e
-
f5250e
     return m;
f5250e
 }