Tue Mar 7 20:17:12 2017 UTC ()
Apply patch (requested by mrg in ticket #1380):
Use arc4random when available to produce the auth cookie.
(80f62c54fbd50a3bbdf9c37258525098c9117830 upstream)


(snj)
diff -r1.1.1.5 -r1.1.1.5.40.1 xsrc/xfree/xc/lib/ICE/iceauth.c

cvs diff -r1.1.1.5 -r1.1.1.5.40.1 xsrc/xfree/xc/lib/ICE/Attic/iceauth.c (expand / switch to unified diff)

--- xsrc/xfree/xc/lib/ICE/Attic/iceauth.c 2003/02/28 13:18:45 1.1.1.5
+++ xsrc/xfree/xc/lib/ICE/Attic/iceauth.c 2017/03/07 20:17:12 1.1.1.5.40.1
@@ -27,74 +27,83 @@ in this Software without prior written a @@ -27,74 +27,83 @@ in this Software without prior written a
27Author: Ralph Mor, X Consortium 27Author: Ralph Mor, X Consortium
28******************************************************************************/ 28******************************************************************************/
29/* $XFree86: xc/lib/ICE/iceauth.c,v 3.6 2002/05/31 18:45:41 dawes Exp $ */ 29/* $XFree86: xc/lib/ICE/iceauth.c,v 3.6 2002/05/31 18:45:41 dawes Exp $ */
30 30
31#include <X11/ICE/ICElib.h> 31#include <X11/ICE/ICElib.h>
32#include "ICElibint.h" 32#include "ICElibint.h"
33#include <X11/ICE/ICEutil.h> 33#include <X11/ICE/ICEutil.h>
34 34
35#include <time.h> 35#include <time.h>
36#define Time_t time_t 36#define Time_t time_t
37 37
38static int binaryEqual (); 38static int binaryEqual ();
39 39
 40#ifdef HAVE_LIBBSD
 41#include <bsd/stdlib.h> /* for arc4random_buf() */
 42#endif
 43
40static int was_called_state; 44static int was_called_state;
41 45
42/* 46/*
43 * MIT-MAGIC-COOKIE-1 is a sample authentication method implemented by 47 * MIT-MAGIC-COOKIE-1 is a sample authentication method implemented by
44 * the SI. It is not part of standard ICElib. 48 * the SI. It is not part of standard ICElib.
45 */ 49 */
46 50
47  51
48char * 52char *
49IceGenerateMagicCookie (len) 53IceGenerateMagicCookie (len)
50 54
51int len; 55int len;
52 56
53{ 57{
54 char *auth; 58 char *auth;
 59#ifndef HAVE_ARC4RANDOM_BUF
55 long ldata[2]; 60 long ldata[2];
56 int seed; 61 int seed;
57 int value; 62 int value;
58 int i; 63 int i;
 64#endif
59  65
60 if ((auth = (char *) malloc (len + 1)) == NULL) 66 if ((auth = (char *) malloc (len + 1)) == NULL)
61 return (NULL); 67 return (NULL);
62 68
 69#ifdef HAVE_ARC4RANDOM_BUF
 70 arc4random_buf(auth, len);
 71#else
63#ifdef ITIMER_REAL 72#ifdef ITIMER_REAL
64 { 73 {
65 struct timeval now; 74 struct timeval now;
66 X_GETTIMEOFDAY (&now); 75 X_GETTIMEOFDAY (&now);
67 ldata[0] = now.tv_sec; 76 ldata[0] = now.tv_sec;
68 ldata[1] = now.tv_usec; 77 ldata[1] = now.tv_usec;
69 } 78 }
70#else 79#else
71 { 80 {
72#ifndef __UNIXOS2__ 81#ifndef __UNIXOS2__
73 long time (); 82 long time ();
74#endif 83#endif
75 ldata[0] = time ((long *) 0); 84 ldata[0] = time ((long *) 0);
76 ldata[1] = getpid (); 85 ldata[1] = getpid ();
77 } 86 }
78#endif 87#endif
79 seed = (ldata[0]) + (ldata[1] << 16); 88 seed = (ldata[0]) + (ldata[1] << 16);
80 srand (seed); 89 srand (seed);
81 for (i = 0; i < len; i++) 90 for (i = 0; i < len; i++)
82 { 91 {
83 value = rand (); 92 value = rand ();
84 auth[i] = value & 0xff; 93 auth[i] = value & 0xff;
85 } 94 }
 95#endif
86 auth[len] = '\0'; 96 auth[len] = '\0';
87 
88 return (auth); 97 return (auth);
89} 98}
90 99
91 100
92  101
93IcePoAuthStatus 102IcePoAuthStatus
94_IcePoMagicCookie1Proc (iceConn, authStatePtr, cleanUp, swap, 103_IcePoMagicCookie1Proc (iceConn, authStatePtr, cleanUp, swap,
95 authDataLen, authData, replyDataLenRet, replyDataRet, errorStringRet) 104 authDataLen, authData, replyDataLenRet, replyDataRet, errorStringRet)
96 105
97IceConn iceConn; 106IceConn iceConn;
98IcePointer *authStatePtr; 107IcePointer *authStatePtr;
99Bool cleanUp; 108Bool cleanUp;
100Bool swap; 109Bool swap;