Changeset 4790:c1073581d7c2 in roaraudio


Ignore:
Timestamp:
03/11/11 11:25:22 (13 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

added support for long (> sizeof(mes.data)-4) cookies, fixed memory use-after-free bug in roard

Files:
6 edited

Legend:

Unmodified
Added
Removed
  • include/libroar/memmgr.h

    r4708 r4790  
    9898#define ROAR_MLOCK _ROAR_MLOCK 
    9999 
     100// aux functions: 
     101void * roar_mm_memdup(const void * s, size_t len); 
     102 
    100103#endif 
    101104 
  • libroar/auth.c

    r4788 r4790  
    133133 char                  * header = mes.data; 
    134134 int                     ret; 
     135 char                  * data = NULL; 
    135136 
    136137 memset(&mes, 0, sizeof(struct roar_message)); // make valgrind happy! 
     
    139140 mes.datalen = 4 + authmes->len; 
    140141 
    141  if ( mes.datalen > sizeof(mes.data) ) 
    142   return -1; 
     142 if ( mes.datalen > sizeof(mes.data) ) { 
     143  data = malloc(mes.datalen); 
     144  if ( data == NULL ) 
     145   return -1; 
     146 
     147  header   = data; 
     148 } 
    143149 
    144150 header[0] = authmes->type; 
     
    148154 
    149155 if ( authmes->len ) { 
    150   memcpy(mes.data + 4, authmes->data, authmes->len); 
    151  } 
    152  
    153  if ( (ret = roar_req(con, &mes, NULL)) == -1 ) { 
     156  if ( data == NULL ) { 
     157   memcpy(mes.data + 4, authmes->data, authmes->len); 
     158  } else { 
     159   memcpy(data + 4, authmes->data, authmes->len); 
     160  } 
     161 } 
     162 
     163 if ( (ret = roar_req(con, &mes, &data)) == -1 ) { 
    154164  authmes->type = -1; 
    155165  return -1; 
    156166 } 
    157167 
     168 if ( data != NULL ) { 
     169  header = data; 
     170 } else { 
     171  header = mes.data; 
     172 } 
     173 
    158174 if ( mes.cmd != ROAR_CMD_OK ) { 
     175  if ( data != NULL ) { 
     176   // we currently do not support long error frames. 
     177   free(data); 
     178   return -1; 
     179  } 
     180 
    159181  ret = -1; 
    160182  if ( roar_err_parsemsg(&mes, &error_frame) == -1 ) { 
     
    177199 authmes->reserved.c[0] = header[2]; 
    178200 authmes->reserved.c[1] = header[3]; 
     201 
     202 if ( data != NULL ) 
     203  free(data); 
    179204 
    180205 return ret; 
  • libroar/authfile.c

    r4787 r4790  
    166166 } 
    167167 
    168  ret->data = ret + sizeof(struct roar_authfile_key) + addrlen; 
     168 ret->data = (void*)ret + sizeof(struct roar_authfile_key) + addrlen; 
    169169 
    170170 ret->len  = len; 
  • libroar/libroar.c

    r4708 r4790  
    8686} 
    8787 
     88void * roar_mm_memdup(const void * s, size_t len) { 
     89 void * ret = roar_mm_malloc(len); 
     90 
     91 if ( ret == NULL ) 
     92  return NULL; 
     93 
     94 memcpy(ret, s, len); 
     95 
     96 return ret; 
     97} 
     98 
    8899//ll 
  • roard/req.c

    r4780 r4790  
    115115  return -1; 
    116116 
    117  ROAR_INFO("req_on_auth(client=%i,...): authtype=%s(%i)", ROAR_DBG_INFO_VERBOSE, 
    118                            client, roar_autht2str(authmes.type), authmes.type); 
     117 ROAR_INFO("req_on_auth(client=%i,...): authtype=%s(%i), len=%llu bytes", ROAR_DBG_INFO_VERBOSE, 
     118                           client, roar_autht2str(authmes.type), authmes.type, (long long unsigned int)authmes.len); 
    119119 
    120120 ret = auth_client_ckeck(cs, &authmes, &next); 
  • roard/roard.c

    r4789 r4790  
    13741374 struct roar_authfile_key *  key = NULL; 
    13751375 int af_type = ROAR_AUTHFILE_TYPE_AUTO; 
     1376 void * keydata; 
    13761377 
    13771378 if ( type == NULL ) { 
     
    14281429    } 
    14291430 
    1430     if ( auth_addkey_cookie(acclev, key->data, key->len) == -1 ) { 
     1431    keydata = roar_mm_memdup(key->data, key->len); 
     1432 
     1433    if ( keydata == NULL ) { 
     1434     ROAR_WARN("add_authfile(*): Can not allocate memory for key."); 
     1435    } else if ( auth_addkey_cookie(acclev, keydata, key->len) == -1 ) { 
    14311436     ROAR_WARN("add_authfile(*): Can not add key to internal key storage."); 
    14321437    } 
Note: See TracChangeset for help on using the changeset viewer.