Changeset 3910:aecb34063151 in roaraudio


Ignore:
Timestamp:
06/06/10 14:45:46 (14 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

do a lot more checking for invalid client ID

Location:
roard
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • roard/clients.c

    r3825 r3910  
    2626#include "roard.h" 
    2727 
     28#define _CHECK_CID_RET(id,ret) if ( (id) < 0 || (id) > ROAR_CLIENTS_MAX || g_clients[(id)] == NULL ) return (ret) 
     29#define _CHECK_CID(id)         _CHECK_CID_RET((id), -1) 
     30 
    2831int clients_init (void) { 
    2932 int i; 
     
    3942 
    4043 for (i = 0; i < ROAR_CLIENTS_MAX; i++) 
    41   if ( g_clients[i] ) 
     44  if ( g_clients[i] != NULL ) 
    4245   clients_delete(i); 
    4346 
     
    126129 ROAR_DBG("clients_delete(id=%i) = ?", id); 
    127130 
    128  if ( g_clients[id] == NULL ) 
    129   return -1; 
     131 _CHECK_CID(id); 
    130132 
    131133 if (g_clients[id]->execed != -1) { 
     
    152154 
    153155int clients_get       (int id, struct roar_client ** client) { 
     156 _CHECK_CID(id); 
     157 
    154158 *client = g_clients[id]; 
    155159 
     
    167171#endif 
    168172 
     173 _CHECK_CID(id); 
     174 
    169175 if ( (c = g_clients[id]) == NULL ) 
    170176  return -1; 
     
    192198 
    193199int clients_get_fh    (int id) { 
    194  if ( g_clients[id] == NULL ) 
    195   return -1; 
     200 _CHECK_CID(id); 
    196201 
    197202 return g_clients[id]->fh; 
     
    199204 
    200205int clients_set_pid   (int id, int    pid) { 
    201  if ( g_clients[id] == NULL ) 
    202   return -1; 
     206 _CHECK_CID(id); 
    203207 
    204208 g_clients[id]->pid = pid; 
     
    208212 
    209213int clients_set_uid   (int id, int    uid) { 
    210  if ( g_clients[id] == NULL ) 
    211   return -1; 
     214 _CHECK_CID(id); 
    212215 
    213216 g_clients[id]->uid = uid; 
     
    217220 
    218221int clients_set_gid   (int id, int    gid) { 
    219  if ( g_clients[id] == NULL ) 
    220   return -1; 
     222 _CHECK_CID(id); 
    221223 
    222224 g_clients[id]->gid = gid; 
     
    228230 int byteorder = ROAR_BYTEORDER_UNKNOWN; 
    229231 
    230  if ( g_clients[id] == NULL ) 
    231   return -1; 
     232 _CHECK_CID(id); 
    232233 
    233234 switch (proto) { 
     
    412413 int rv = 0; 
    413414 
    414  if ( g_clients[id] == NULL ) 
    415   return -1; 
     415 _CHECK_CID(id); 
     416 
    416417 if ( g_clients[id]->fh == -1 ) 
    417418  return -1; 
     
    554555 int i; 
    555556 
     557 _CHECK_CID(client); 
     558 
     559#if 0 
    556560 if ( g_clients[client] == NULL ) { 
    557561  ROAR_WARN("client_stream_exec(client=%i, stream=%i) = -1 // client does not exist", client, stream); 
    558562  return -1; 
    559563 } 
     564#endif 
    560565 
    561566 for (i = 0; i < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; i++) { 
     
    576581 int i; 
    577582 
    578  if ( g_clients[client] == NULL ) 
    579   return -1; 
     583 _CHECK_CID(client); 
    580584 
    581585 for (i = 0; i < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; i++) { 
     
    592596 int i; 
    593597 
    594  if ( g_clients[client] == NULL ) 
    595   return -1; 
     598 _CHECK_CID(client); 
    596599 
    597600 for (i = 0; i < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; i++) { 
     
    609612 int i; 
    610613 
    611  if ( g_clients[client] == NULL ) 
    612   return -1; 
     614 _CHECK_CID(client); 
    613615 
    614616 for (i = 0; i < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; i++) { 
  • roard/network.c

    r3802 r3910  
    100100 client = clients_new(); 
    101101 
     102 if ( client == -1 ) { 
     103  ROAR_DBG("net_get_new_client(void) = -1 // can not create new client"); 
     104  return -1; 
     105 } 
     106 
    102107 if ( clients_set_fh(client, fh) == -1 ) { 
    103108  ROAR_ERR("net_get_new_client(void): Can not set client's fh"); 
Note: See TracChangeset for help on using the changeset viewer.