From ac8243334cd14ffcf8f407cb5fbee89d4790d389 Mon Sep 17 00:00:00 2001 From: =?utf8?q?R=C3=A9mi=20Denis-Courmont?= Date: Sat, 6 Mar 2010 12:21:02 +0200 Subject: [PATCH] Thread-safe random numbers for session IDs --- modules/misc/rtsp.c | 7 +++++-- modules/stream_out/rtsp.c | 4 ++-- src/network/httpd.c | 4 +++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/modules/misc/rtsp.c b/modules/misc/rtsp.c index d88522e471..7f4ae09c4d 100644 --- a/modules/misc/rtsp.c +++ b/modules/misc/rtsp.c @@ -42,6 +42,7 @@ #include #include #include +#include #ifndef WIN32 # include @@ -1019,7 +1020,8 @@ static int RtspCallback( httpd_callback_sys_t *p_args, httpd_client_t *cl, answer->p_body = NULL; break; } - if( asprintf( &psz_new, "%d", rand() ) < 0 ) +#warning Should use secure randomness here! (spoofing risk) + if( asprintf( &psz_new, "%lu", vlc_mrand48() ) < 0 ) return VLC_ENOMEM; psz_session = psz_new; @@ -1358,7 +1360,8 @@ static int RtspCallbackES( httpd_callback_sys_t *p_args, httpd_client_t *cl, answer->p_body = NULL; break; } - if( asprintf( &psz_new, "%d", rand() ) < 0 ) +#warning Session ID should be securely random (spoofing risk) + if( asprintf( &psz_new, "%lu", vlc_mrand48() ) < 0 ) return VLC_ENOMEM; psz_session = psz_new; diff --git a/modules/stream_out/rtsp.c b/modules/stream_out/rtsp.c index 0d103fa6d2..e237c03864 100644 --- a/modules/stream_out/rtsp.c +++ b/modules/stream_out/rtsp.c @@ -538,8 +538,8 @@ static int RtspHandler( rtsp_stream_t *rtsp, rtsp_stream_id_t *id, if( psz_session == NULL ) { /* Create a dummy session ID */ - snprintf( psz_sesbuf, sizeof( psz_sesbuf ), "%d", - rand() ); + snprintf( psz_sesbuf, sizeof( psz_sesbuf ), "%lu", + vlc_mrand48() ); psz_session = psz_sesbuf; } answer->i_status = 200; diff --git a/src/network/httpd.c b/src/network/httpd.c index 1fec831e1e..8dbdbf5878 100644 --- a/src/network/httpd.c +++ b/src/network/httpd.c @@ -36,6 +36,7 @@ #include #include #include +#include #include "../libvlc.h" #include @@ -825,7 +826,8 @@ static int httpd_StreamCallBack( httpd_callback_sys_t *p_sys, "application/octet-stream" ); httpd_MsgAdd( answer, "Server", "Cougar 4.1.0.3921" ); httpd_MsgAdd( answer, "Pragma", "no-cache" ); - httpd_MsgAdd( answer, "Pragma", "client-id=%d", rand()&0x7fff ); + httpd_MsgAdd( answer, "Pragma", "client-id=%lu", + vlc_mrand48()&0x7fff ); httpd_MsgAdd( answer, "Pragma", "features=\"broadcast\"" ); /* Check if there is a xPlayStrm=1 */ -- 2.39.2