Mercurial > urweb
changeset 2105:882556b3029d
Fix silly mistake from last commit; also switch away from rand() in openssl.c
author | Adam Chlipala <adam@chlipala.net> |
---|---|
date | Thu, 22 Jan 2015 09:46:20 -0500 |
parents | 7755f00a4fc3 |
children | 18ef1db770f6 |
files | src/c/openssl.c src/c/urweb.c |
diffstat | 2 files changed, 8 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/src/c/openssl.c Mon Jan 12 12:02:54 2015 -0500 +++ b/src/c/openssl.c Thu Jan 22 09:46:20 2015 -0500 @@ -9,6 +9,7 @@ #include <string.h> #include <openssl/sha.h> +#include <openssl/rand.h> #define PASSSIZE 4 @@ -19,10 +20,11 @@ char *uw_sig_file = NULL; static void random_password() { - int i; - - for (i = 0; i < PASSSIZE; ++i) - password[i] = rand(); + if (!RAND_bytes((unsigned char *)password, sizeof password)) { + fprintf(stderr, "Error generating random password\n"); + perror("RAND_bytes"); + exit(1); + } } void uw_init_crypto() {
--- a/src/c/urweb.c Mon Jan 12 12:02:54 2015 -0500 +++ b/src/c/urweb.c Thu Jan 22 09:46:20 2015 -0500 @@ -171,11 +171,11 @@ static uw_Basis_int my_rand() { pthread_mutex_lock(&rand_mutex); - int r = RAND_bytes((unsigned char *)&ret, sizeof ret); + int ret, r = RAND_bytes((unsigned char *)&ret, sizeof ret); pthread_mutex_unlock(&rand_mutex); if (r) - return abs(r); + return abs(ret); else return -1; } @@ -362,8 +362,6 @@ extern void uw_init_crypto(); void uw_global_init() { - srand(time(NULL) ^ getpid()); - clients = malloc(0); uw_global_custom();