Changeset 2911 for releases

Show
Ignore:
Timestamp:
04/26/06 10:07:18 (3 years ago)
Author:
aj
Message:

fix a memory leak.
don't access buffer beyond length.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • releases/opensc-0.11.0/src/libopensc/apdu.c

    r2868 r2911  
    203203                return SC_ERROR_MEMORY_FAILURE; 
    204204        /* encode the APDU in the buffer */ 
    205         if (sc_apdu2bytes(ctx, apdu, proto, nbuf, nlen) != SC_SUCCESS) 
     205        if (sc_apdu2bytes(ctx, apdu, proto, nbuf, nlen) != SC_SUCCESS) { 
     206                free(nbuf); 
    206207                return SC_ERROR_INTERNAL; 
     208        } 
    207209        *buf = nbuf; 
    208210        *len = nlen; 
     
    225227        len -= 2; 
    226228        /* set output length and copy the returned data if necessary */ 
    227         if (len <= apdu->resplen) 
     229        if (apdu->resplen >= len) { 
    228230                apdu->resplen = len; 
    229  
    230         if (apdu->resplen != 0) 
    231231                memcpy(apdu->resp, buf, apdu->resplen); 
     232        } 
    232233 
    233234        return SC_SUCCESS;