]> git.sesse.net Git - vlc/blobdiff - src/network/httpd.c
Add some more assert()s for unchecked malloc().
[vlc] / src / network / httpd.c
index c29250f61edac4226b46defcc318aeb7a7703b00..2ccac340a1fc4460230c7ff1c9762b81ef2682bc 100644 (file)
@@ -461,6 +461,7 @@ httpd_file_t *httpd_FileNew( httpd_host_t *host,
                              httpd_file_sys_t *p_sys )
 {
     httpd_file_t *file = malloc( sizeof( httpd_file_t ) );
+    assert( file );
 
     if( ( file->url = httpd_UrlNewUnique( host, psz_url, psz_user,
                                           psz_password, p_acl )
@@ -593,6 +594,7 @@ httpd_HandlerCallBack( httpd_callback_sys_t *p_sys, httpd_client_t *cl,
         answer->i_body = sizeof("HTTP/1.0 xxx \r\n")
                         + strlen(psz_status) + i_headers - 1;
         psz_new = (char *)malloc( answer->i_body + 1);
+        assert( psz_new );
         sprintf( psz_new, "HTTP/1.0 %03d %s\r\n", i_status, psz_status );
         memcpy( &psz_new[strlen(psz_new)], psz_headers, i_headers );
         free( answer->p_body );
@@ -610,6 +612,7 @@ httpd_handler_t *httpd_HandlerNew( httpd_host_t *host, const char *psz_url,
                                    httpd_handler_sys_t *p_sys )
 {
     httpd_handler_t *handler = malloc( sizeof( httpd_handler_t ) );
+    assert( handler );
 
     if( ( handler->url = httpd_UrlNewUnique( host, psz_url, psz_user,
                                              psz_password, p_acl )
@@ -681,6 +684,7 @@ httpd_redirect_t *httpd_RedirectNew( httpd_host_t *host, const char *psz_url_dst
                                      const char *psz_url_src )
 {
     httpd_redirect_t *rdir = malloc( sizeof( httpd_redirect_t ) );
+    assert( rdir );
 
     if( !( rdir->url = httpd_UrlNewUnique( host, psz_url_src, NULL, NULL, NULL ) ) )
     {
@@ -787,6 +791,7 @@ static int httpd_StreamCallBack( httpd_callback_sys_t *p_sys,
 
         answer->i_body = i_write;
         answer->p_body = malloc( i_write );
+        assert( answer->p_body );
         memcpy( answer->p_body, &stream->p_buffer[i_pos], i_write );
 
         answer->i_body_offset += i_write;
@@ -810,6 +815,7 @@ static int httpd_StreamCallBack( httpd_callback_sys_t *p_sys,
             {
                 answer->i_body = stream->i_header;
                 answer->p_body = malloc( stream->i_header );
+                assert( answer->p_body );
                 memcpy( answer->p_body, stream->p_header, stream->i_header );
             }
             answer->i_body_offset = stream->i_buffer_last_pos;
@@ -863,6 +869,7 @@ httpd_stream_t *httpd_StreamNew( httpd_host_t *host,
                                  const vlc_acl_t *p_acl )
 {
     httpd_stream_t *stream = malloc( sizeof( httpd_stream_t ) );
+    assert( stream );
 
     if( ( stream->url = httpd_UrlNewUnique( host, psz_url, psz_user,
                                             psz_password, p_acl )
@@ -884,6 +891,7 @@ httpd_stream_t *httpd_StreamNew( httpd_host_t *host,
     stream->p_header = NULL;
     stream->i_buffer_size = 5000000;    /* 5 Mo per stream */
     stream->p_buffer = malloc( stream->i_buffer_size );
+    assert( stream->p_buffer );
     /* We set to 1 to make life simpler
      * (this way i_body_offset can never be 0) */
     stream->i_buffer_pos = 1;
@@ -909,6 +917,7 @@ int httpd_StreamHeader( httpd_stream_t *stream, uint8_t *p_data, int i_data )
     if( i_data > 0 )
     {
         stream->p_header = malloc( i_data );
+        assert( stream->p_header );
         memcpy( stream->p_header, p_data, i_data );
     }
     vlc_mutex_unlock( &stream->lock );
@@ -1239,6 +1248,7 @@ static httpd_url_t *httpd_UrlNewPrivate( httpd_host_t *host, const char *psz_url
     }
 
     url = malloc( sizeof( httpd_url_t ) );
+    assert( url );
     url->host = host;
 
     vlc_mutex_init( &url->lock );
@@ -1407,6 +1417,7 @@ static void httpd_ClientInit( httpd_client_t *cl, mtime_t now )
     cl->i_buffer_size = HTTPD_CL_BUFSIZE;
     cl->i_buffer = 0;
     cl->p_buffer = malloc( cl->i_buffer_size );
+    assert( cl->p_buffer );
     cl->i_mode   = HTTPD_CLIENT_FILE;
     cl->b_read_waiting = false;
 
@@ -1555,6 +1566,7 @@ static void httpd_ClientRecv( httpd_client_t *cl )
             cl->query.i_channel = cl->p_buffer[1];
             cl->query.i_body  = (cl->p_buffer[2] << 8)|cl->p_buffer[3];
             cl->query.p_body  = malloc( cl->query.i_body );
+            assert( cl->query.p_body );
             cl->i_buffer      -= 4;
             memcpy( cl->query.p_body, cl->p_buffer + 4, cl->i_buffer );
         }
@@ -1836,6 +1848,7 @@ static void httpd_ClientRecv( httpd_client_t *cl )
                      * request and close the connection
                      * to mark and of body (probably only RTSP) */
                     cl->query.p_body = malloc( cl->query.i_body );
+                    assert( cl->query.p_body );
                     cl->i_buffer = 0;
                 }
                 else
@@ -1924,6 +1937,7 @@ static void httpd_ClientSend( httpd_client_t *cl )
             cl->i_buffer_size = i_size;
             free( cl->p_buffer );
             cl->p_buffer = malloc( i_size );
+            assert( cl->p_buffer );
         }
         p = (char *)cl->p_buffer;
 
@@ -2367,6 +2381,7 @@ static void* httpd_HostThread( void *data )
                         cl->i_buffer_size = 1000;
                         free( cl->p_buffer );
                         cl->p_buffer = malloc( cl->i_buffer_size );
+                        assert( cl->p_buffer );
                         cl->i_state = HTTPD_CLIENT_RECEIVING;
                     }
                     else
@@ -2385,6 +2400,7 @@ static void* httpd_HostThread( void *data )
                     cl->i_buffer_size = 1000;
                     free( cl->p_buffer );
                     cl->p_buffer = malloc( cl->i_buffer_size );
+                    assert( cl->p_buffer );
                     cl->i_state = HTTPD_CLIENT_RECEIVING;
                     cl->b_read_waiting = false;
                 }