Changeset 5589 for pjproject


Ignore:
Timestamp:
May 4, 2017 5:22:44 AM (8 years ago)
Author:
ming
Message:

Re #1994 (misc): Fixes bugs in base64

  • move access to input parameter variable after the assertion to check the variable.
  • prevent invalid memory access for empty input string
  • allow using an output buffer of just the right size

Thanks to Adrien Béraud for the patch

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjlib-util/src/pjlib-util/base64.c

    r4713 r5589  
    125125                                     pj_uint8_t *out, int *out_len) 
    126126{ 
    127     const char *buf = input->ptr; 
    128     int len = (int)input->slen; 
     127    const char *buf; 
     128    int len; 
    129129    int i, j, k; 
    130130    int c[4]; 
     
    132132    PJ_ASSERT_RETURN(input && out && out_len, PJ_EINVAL); 
    133133 
    134     while (buf[len-1] == '=' && len) 
     134    buf = input->ptr; 
     135    len = (int)input->slen; 
     136    while (len && buf[len-1] == '=') 
    135137        --len; 
    136138 
     
    162164    } 
    163165 
    164     pj_assert(j < *out_len); 
     166    pj_assert(j <= *out_len); 
    165167    *out_len = j; 
    166168 
Note: See TracChangeset for help on using the changeset viewer.