Browse Source

abandon usage of random()

Change-Id: I870fd7963dc9148b496361892a2bfe2cc0f88690
changes/55/12455/1
Richard Fuchs 9 years ago
parent
commit
7182e751a1
3 changed files with 9 additions and 3 deletions
  1. +7
    -1
      daemon/aux.h
  2. +1
    -1
      daemon/ice.c
  3. +1
    -1
      daemon/media_socket.c

+ 7
- 1
daemon/aux.h View File

@ -19,6 +19,7 @@
#include <math.h>
#include "compat.h"
#include <openssl/rand.h>
#include <assert.h>
#if !(GLIB_CHECK_VERSION(2,30,0))
#define g_atomic_int_and(atomic, val) \
@ -185,7 +186,12 @@ INLINE int strmemcmp(const void *mem, int len, const char *str) {
}
INLINE void random_string(unsigned char *buf, int len) {
RAND_bytes(buf, len);
assert(RAND_bytes(buf, len) == 1);
}
INLINE long int ssl_random() {
long int ret;
random_string((void *) &ret, sizeof(ret));
return ret;
}
INLINE const char *__get_enum_array_text(const char * const *array, unsigned int idx,


+ 1
- 1
daemon/ice.c View File

@ -1372,7 +1372,7 @@ sleep:
static void random_ice_string(char *buf, int len) {
while (len--)
*buf++ = ice_chars[random() % strlen(ice_chars)];
*buf++ = ice_chars[ssl_random() % strlen(ice_chars)];
}
static void create_random_ice_string(struct call *call, str *s, int len) {


+ 1
- 1
daemon/media_socket.c View File

@ -648,7 +648,7 @@ int __get_consecutive_ports(GQueue *out, unsigned int num_ports, unsigned int wa
port = g_atomic_int_get(&pp->last_used);
__C_DBG("before randomization port=%d", port);
#if PORT_RANDOM_MIN && PORT_RANDOM_MAX
port += PORT_RANDOM_MIN + (random() % (PORT_RANDOM_MAX - PORT_RANDOM_MIN));
port += PORT_RANDOM_MIN + (ssl_random() % (PORT_RANDOM_MAX - PORT_RANDOM_MIN));
#endif
__C_DBG("after randomization port=%d", port);
}


Loading…
Cancel
Save