Codebase list libcrypt-ssleay-perl / 92bc52a
Use a define'd constant rather than sizeof In `SSL_CTX_new`, if loading from `/dev/urandom` fails, the contents of a local char array is used as a seed source. The size of this memory block is passed using sizeof, but if the argument was ever changed to be `char *`, this would not be good. So, instead, use a define'd constant. A. Sinan Unur 10 years ago
1 changed file(s) with 10 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
110110
111111 MODULE = Crypt::SSLeay PACKAGE = Crypt::SSLeay::CTX PREFIX = SSL_CTX_
112112
113 #define CRYPT_SSLEAY_RAND_BUFSIZE 1024
114
113115 SSL_CTX*
114116 SSL_CTX_new(packname, ssl_version)
115117 SV* packname
117119 CODE:
118120 SSL_CTX* ctx;
119121 static int bNotFirstTime;
120 char buf[1024];
122 char buf[ CRYPT_SSLEAY_RAND_BUFSIZE ];
121123 int rand_bytes_read;
122124
123125 if(!bNotFirstTime) {
130132
131133 /**** Code from Devin Heitmueller, 10/3/2002 ****/
132134 /**** Use /dev/urandom to seed if available ****/
135 /* see also
136 * http://sockpuppet.org/blog/2014/02/25/safely-generate-random-numbers/
137 */
138 /* Also, http://wiki.openssl.org/index.php/Random_Numbers#Seeds
139 * seems to indicate maybe we should not be doing this ourselves
140 */
133141 rand_bytes_read = RAND_load_file("/dev/urandom", 1024);
134142 if (rand_bytes_read <= 0) {
135143 /* Couldn't read /dev/urandom, just seed off
136144 * of the stack variable (the old way)
137145 */
138 RAND_seed(buf,sizeof buf);
146 RAND_seed(buf, CRYPT_SSLEAY_RAND_BUFSIZE);
139147 }
140148
141149 if(ssl_version == 23) {