Changeset 99f3e5493956c0cc4df7416df2da23cc7d4fd55d

Show
Ignore:
Timestamp:
11/07/02 17:54:39 (6 years ago)
Author:
Gildas Bazin <gbazin@videolan.org>
git-committer:
Gildas Bazin <gbazin@videolan.org> 1036688079 +0000
git-parent:

[85071f3419dec4837538a25f0ab8853cd6ddf531]

git-author:
Gildas Bazin <gbazin@videolan.org> 1036688079 +0000
Message:

* modules/access/http.c: don't crash, but complain on non http/1.x streams.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/access/http.c

    r0e24796 r99f3e54  
    33 ***************************************************************************** 
    44 * Copyright (C) 2001, 2002 VideoLAN 
    5  * $Id: http.c,v 1.5 2002/10/07 21:58:40 massiot Exp $ 
     5 * $Id: http.c,v 1.6 2002/11/07 16:54:39 gbazin Exp $ 
    66 * 
    77 * Authors: Christophe Massiot <massiot@via.ecp.fr> 
     
    9797    char                psz_buffer[256]; 
    9898    byte_t *            psz_parser; 
    99     int                 i_returncode, i
     99    int                 i_returncode, i, i_size
    100100    char *              psz_return_alpha; 
    101101 
     
    161161 
    162162    /* get the returncode */ 
    163     if( input_Peek( p_input, &psz_parser, MAX_LINE ) <= 0 ) 
     163    if( (i_size = input_Peek( p_input, &psz_parser, MAX_LINE )) <= 0 ) 
    164164    { 
    165165        msg_Err( p_input, "not enough data" ); 
     
    168168    } 
    169169 
    170     if( !strncmp( psz_parser, "HTTP/1.", 
    171                   strlen("HTTP/1.") ) ) 
    172     { 
    173         psz_parser += strlen("HTTP 1.") + 2
     170    if( (i_size >= sizeof("HTTP/1.") + 1 ) && 
     171   !strncmp( psz_parser, "HTTP/1.", sizeof("HTTP/1.") - 1 ) ) 
     172    { 
     173        psz_parser += sizeof("HTTP/1.") + 1
    174174        i_returncode = atoi( (char*)psz_parser ); 
    175175        msg_Dbg( p_input, "HTTP server replied: %i", i_returncode ); 
    176176        psz_parser += 4; 
    177         for ( i = 0; psz_parser[i] != '\r' || psz_parser[i+1] != '\n'; i++ ) 
     177    i_size -= (sizeof("HTTP/1.") + 5); 
     178        for ( i = 0; (i < i_size -1) && ((psz_parser[i] != '\r') || 
     179          (psz_parser[i+1] != '\n')); i++ ) 
    178180        { 
    179181            ; 
    180182        } 
     183     /* check we actually parsed something */ 
     184        if ( (i == i_size - 1) && (psz_parser[i+1] != '\n') ) 
     185        { 
     186            msg_Err( p_input, "stream not compliant with HTTP/1.x" ); 
     187            return -1; 
     188        } 
     189 
    181190        psz_return_alpha = malloc( i + 1 ); 
    182191        memcpy( psz_return_alpha, psz_parser, i ); 
     
    188197        return -1; 
    189198    } 
    190      
     199 
    191200    if ( i_returncode >= 400 ) /* something is wrong */ 
    192201    {