]> git.sesse.net Git - vlc/commitdiff
Thread-safe random numbers for session IDs
authorRémi Denis-Courmont <remi@remlab.net>
Sat, 6 Mar 2010 10:21:02 +0000 (12:21 +0200)
committerRémi Denis-Courmont <remi@remlab.net>
Sat, 6 Mar 2010 10:30:06 +0000 (12:30 +0200)
modules/misc/rtsp.c
modules/stream_out/rtsp.c
src/network/httpd.c

index d88522e471e36bddefd859d76e023891b1620f4a..7f4ae09c4d47b43b18a8c90855d97bc9e5e4eece 100644 (file)
@@ -42,6 +42,7 @@
 #include <vlc_network.h>
 #include <vlc_charset.h>
 #include <vlc_strings.h>
+#include <vlc_rand.h>
 
 #ifndef WIN32
 # include <locale.h>
@@ -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;
 
index 0d103fa6d2960be6ca6ca461d15e3b66f8a381d2..e237c0386494ecbda87f3ca6acca9a99b2f34a24 100644 (file)
@@ -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;
index 1fec831e1e8b02fc8b696fbeaf5cb899eb96c57c..8dbdbf5878edecdd480432d46d9c71b2d6e8e0ab 100644 (file)
@@ -36,6 +36,7 @@
 #include <vlc_tls.h>
 #include <vlc_acl.h>
 #include <vlc_strings.h>
+#include <vlc_rand.h>
 #include "../libvlc.h"
 
 #include <string.h>
@@ -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 */