Changeset 34 in cheroxy for trunk/src/CRXProxy.cpp


Ignore:
Timestamp:
11/20/12 16:31:22 (11 years ago)
Author:
cheese
Message:

#1 fix crash bug for memcpy on getting request/response message from CRXProxy

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/CRXProxy.cpp

    r28 r34  
    141141                          const int aBufferSize) const
    142142{
    143     void * aPtr = static_cast<void *> (aBuffer);
     143    void        * aPtr = static_cast<void *> (aBuffer);
     144
     145    int         aCopyLength     = 0;
     146    int         aRemainLength   = aBufferSize;
     147    const int   aHeaderLength   = mHttpRequest.GetHeader ().length ();
    144148
    145149    /*----------------------------------------------------------------*/
     
    147151        return NULL;
    148152   
    149     if (aBufferSize > 0)
    150         memcpy (aPtr, mHttpRequest.GetHeader ().c_str (), aBufferSize);
     153    aCopyLength = aRemainLength < aHeaderLength ? aBufferSize : aHeaderLength;
     154    if (aCopyLength > 0)
     155        memcpy (aPtr, mHttpRequest.GetHeader ().c_str (), aCopyLength);
    151156    /*----------------------------------------------------------------*/
    152157
     
    175180                           const int    aBufferSize) const
    176181{
    177     void    * aPtr = static_cast<void *> (aBuffer);
    178 
    179     int     aRemainLength = aBufferSize;
     182    void        * aPtr = static_cast<void *> (aBuffer);
     183
     184    int         aCopyLength     = 0;
     185    int         aRemainLength   = aBufferSize;
     186    const int   aHeaderLength   = mHttpResponse.GetHeader ().length ();
     187    const int   aContentLength  = mHttpResponse.GetContentLength ();
    180188
    181189    /*----------------------------------------------------------------*/
     
    183191        return NULL;
    184192
    185     if (aRemainLength > 0)
    186         memcpy (aPtr, mHttpResponse.GetHeader ().c_str (), aRemainLength);
    187 
    188     aRemainLength -= mHttpResponse.GetHeader ().length ();
    189 
    190     if (aRemainLength > 0)
    191         memcpy (aPtr, mHttpResponse.GetContentBody (), aRemainLength);
     193    aCopyLength = aRemainLength < aHeaderLength ? aBufferSize : aHeaderLength;
     194    if (aCopyLength > 0)
     195        memcpy (aPtr, mHttpResponse.GetHeader ().c_str (), aCopyLength);
     196
     197    aRemainLength -= aCopyLength;
     198
     199    aCopyLength = aRemainLength < aContentLength ? aRemainLength : aContentLength;
     200    if (aCopyLength > 0)
     201        memcpy (aPtr, mHttpResponse.GetContentBody (), aCopyLength);
    192202    /*----------------------------------------------------------------*/
    193203
Note: See TracChangeset for help on using the changeset viewer.