]> git.sesse.net Git - vlc/commitdiff
Fix off-by-one buffer overflow
authorRémi Denis-Courmont <rem@videolan.org>
Thu, 5 Oct 2006 16:21:45 +0000 (16:21 +0000)
committerRémi Denis-Courmont <rem@videolan.org>
Thu, 5 Oct 2006 16:21:45 +0000 (16:21 +0000)
modules/control/http/http.c

index 918c712cfdeff8326319ce496aba2ec8d0f4310f..cf6b1ff35e678e5ae2c31f655f949608dcba8f12 100644 (file)
@@ -124,7 +124,6 @@ static int Open( vlc_object_t *p_this )
                   *psz_crl = NULL;
     int           i_port       = 0;
     char          *psz_src;
-    char          *psz_tmp;
 
     var_Create(p_intf->p_libvlc_global, "http-host", VLC_VAR_STRING );
     psz_address=var_GetString(p_intf->p_libvlc_global, "http-host");
@@ -263,14 +262,6 @@ static int Open( vlc_object_t *p_this )
             i_port= 8080;
     }
 
-    /* maximum port is 65535 , strlen("65535") = 5 , + ':' = 6 */
-    psz_tmp = malloc( ( strlen( psz_address ) + 6 ) * sizeof( char) );
-
-    /* Ugly hack to allow to run several HTTP servers on different ports. */
-    sprintf( psz_tmp, "%s:%d", psz_address, i_port + 1 );
-    var_SetString( p_intf->p_libvlc_global, "http-host", psz_tmp );
-    free( psz_tmp );
-
     msg_Dbg( p_intf, "base %s:%d", psz_address, i_port );
 
     p_sys->p_httpd_host = httpd_TLSHostNew( VLC_OBJECT(p_intf), psz_address,
@@ -284,6 +275,14 @@ static int Open( vlc_object_t *p_this )
         free( p_sys );
         return VLC_EGENERIC;
     }
+    else
+    {
+        char psz_tmp[NI_MAXHOST + 6];
+
+        /* Ugly hack to run several HTTP servers on different ports */
+        snprintf( psz_tmp, sizeof (psz_tmp), "%s:%d", psz_address, i_port + 1 );
+        var_SetString( p_intf->p_libvlc_global, "http-host", psz_tmp );
+    }
 
     p_sys->i_files  = 0;
     p_sys->pp_files = NULL;