Index: ChangeLog
===================================================================
--- ChangeLog	(revision 5143)
+++ ChangeLog	(revision 5145)
@@ -4,4 +4,9 @@
 	* Fixed invalid pointer aliasing (Closes: #178)
 	* Fixed segfaul in PortAudio driver(v19) if no device is found.
+	* Fixed invalid pointer aliasing in filter code (pr0)
+	* Fixed remote a local buffer overflow in client to message
+	  converter code as well as a remote attackable overflow in
+	  message to client converter code (pr0)
+	* Updated error handling (pr0)
 
 v. 0.4rc0 - Mon Sep 05 2011 15:25 CEST
Index: libroar/beep.c
===================================================================
--- libroar/beep.c	(revision 4708)
+++ libroar/beep.c	(revision 5145)
@@ -40,6 +40,8 @@
  int16_t * data = (int16_t*)m.data;
 
- if ( con == NULL )
+ if ( con == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
   return -1;
+ }
 
  memset(&m, 0, sizeof(m));
Index: libroar/client.c
===================================================================
--- libroar/client.c	(revision 4948)
+++ libroar/client.c	(revision 5145)
@@ -39,6 +39,8 @@
  int i;
 
- if ( client == NULL )
+ if ( client == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
   return -1;
+ }
 
  memset(client, 0, sizeof(struct roar_client));
@@ -58,6 +60,8 @@
 
 int roar_client_set_fh   (struct roar_client * client, int fh) {
- if ( client == NULL )
+ if ( client == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
   return -1;
+ }
 
  client->fh = fh;
@@ -67,6 +71,8 @@
 
 int roar_client_set_proto(struct roar_client * client, int proto, int byteorder) {
- if ( client == NULL )
+ if ( client == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
   return -1;
+ }
 
  client->proto = proto;
@@ -80,4 +86,5 @@
     break;
    default:
+     roar_err_set(ROAR_ERROR_INVAL);
      return -1;
     break;
@@ -93,4 +100,9 @@
  int confh;
  int i;
+
+ if ( con == NULL || client == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  return -1;
+ }
 
  memset(&m,  0, sizeof(m));
@@ -133,4 +145,9 @@
  int i;
 
+ if ( con == NULL || client == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  return -1;
+ }
+
  memset(&m,  0, sizeof(m));
 
Index: libroar/ctl.c
===================================================================
--- libroar/ctl.c	(revision 5144)
+++ libroar/ctl.c	(revision 5145)
@@ -311,9 +311,13 @@
  m->data[1] = filter;
  m->data[2] = cmp;
- *((uint32_t*)&(m->data[3])) = ROAR_HOST2NET32(id);
+ m->data[3] = (id & 0xFF000000LU) >> 24;
+ m->data[4] = (id & 0x00FF0000LU) >> 16;
+ m->data[5] = (id & 0x0000FF00LU) >>  8;
+ m->data[6] = (id & 0x000000FFLU) >>  0;
 
  return 0;
 }
 int roar_ctl_m2f      (struct roar_message * m, unsigned char * filter, unsigned char * cmp, uint32_t * id) {
+ register uint32_t idreg;
 
  if ( m->datalen != 7 )
@@ -328,5 +332,9 @@
  *cmp    = m->data[2];
 
- *id = ROAR_NET2HOST32(*((uint32_t*)&(m->data[3])));
+ idreg   = ((uint32_t)(unsigned char)m->data[3]) << 24;
+ idreg  |= ((uint32_t)(unsigned char)m->data[4]) << 16;
+ idreg  |= ((uint32_t)(unsigned char)m->data[5]) <<  8;
+ idreg  |= ((uint32_t)(unsigned char)m->data[6]) <<  0;
+ *id     = idreg;
 
  return 0;
@@ -345,4 +353,5 @@
    break;
   default:
+    roar_err_set(ROAR_ERROR_NOTSUP);
     return -1;
  }
@@ -352,6 +361,8 @@
  int i;
 
- if ( len > LIBROAR_BUFFER_MSGDATA )
-  return -1;
+ if ( len > LIBROAR_BUFFER_MSGDATA ) {
+  roar_err_set(ROAR_ERROR_MSGSIZE);
+  return -1;
+ }
 
  m->datalen = len;
@@ -365,6 +376,8 @@
  int i;
 
- if ( m->datalen > len )
-  return -1;
+ if ( m->datalen > len ) {
+  roar_err_set(ROAR_ERROR_MSGSIZE);
+  return -1;
+ }
 
  for (i = 0; i < m->datalen; i++)
@@ -380,5 +393,6 @@
  int max_len;
  uint32_t pid;
- size_t len_rest;
+ signed long int len_rest;
+ size_t nnode_len;
 
  if ( c == NULL )
@@ -429,7 +443,12 @@
  cur += 4;
 
- len_rest = sizeof(m->data) - cur;
- if ( roar_nnode_to_blob(&(c->nnode), &(m->data[cur]), &len_rest) == 0 ) {
-  cur += len_rest;
+ len_rest = (long int)sizeof(m->data) - (long int)cur;
+ if ( len_rest < 0 ) {
+  roar_panic(ROAR_FATAL_ERROR_MEMORY_CORRUPTION, NULL);
+ }
+
+ nnode_len = len_rest;
+ if ( roar_nnode_to_blob(&(c->nnode), &(m->data[cur]), &nnode_len) == 0 ) {
+  cur += nnode_len;
  }
 
@@ -445,9 +464,13 @@
  size_t len;
 
- if ( m == NULL || c == NULL )
-  return -1;
-
- if ( m->datalen == 0 )
-  return -1;
+ if ( m == NULL || c == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  return -1;
+ }
+
+ if ( m->datalen == 0 ) {
+  roar_err_set(ROAR_ERROR_MSGSIZE);
+  return -1;
+ }
 
  ROAR_DBG("roar_ctl_m2c(*): got data!, len = %i", m->datalen);
@@ -455,9 +478,12 @@
  if ( m->data[0] != 0 ) {
   ROAR_DBG("roar_ctl_m2c(*): wrong version!");
-  return -1;
- }
-
- if ( m->datalen < 3 )
-  return -1;
+  roar_err_set(ROAR_ERROR_NSVERSION);
+  return -1;
+ }
+
+ if ( m->datalen < 3 ) {
+  roar_err_set(ROAR_ERROR_MSGSIZE);
+  return -1;
+ }
 
  ROAR_DBG("roar_ctl_m2c(*): have usable data!");
@@ -467,4 +493,9 @@
  for (i = 0; i < ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT; i++)
   c->streams[i] = -1;
+
+ if ( m->data[2] < 0 || m->data[2] > ROAR_CLIENTS_MAX_STREAMS_PER_CLIENT ) {
+  roar_err_set(ROAR_ERROR_TOOMANYARGS);
+  return -1;
+ }
 
  for (i = 0; i < m->data[2]; i++)
@@ -555,4 +586,5 @@
  }
 
+ roar_err_set(ROAR_ERROR_NOENT);
  return -1;
 }
@@ -592,4 +624,5 @@
  }
 
+ roar_err_set(ROAR_ERROR_NOENT);
  return -1;
 }
@@ -632,4 +665,5 @@
    return _libroar_ot[i].ot;
 
+ roar_err_set(ROAR_ERROR_NOENT);
  return -1;
 }
@@ -642,4 +676,5 @@
    return _libroar_ot[i].name;
 
+ roar_err_set(ROAR_ERROR_NOENT);
  return NULL;
 }
@@ -650,6 +685,13 @@
  uint_least32_t s;
 
- if ( dst == NULL || src == NULL || dstchans < 0 || srcchans < 0 )
-  return -1;
+ if ( dst == NULL || src == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  return -1;
+ }
+
+ if ( dstchans < 0 || srcchans < 0 ) {
+  roar_err_set(ROAR_ERROR_INVAL);
+  return -1;
+ }
 
  if ( dstchans == srcchans ) {
@@ -709,4 +751,5 @@
        break;
       default:
+        roar_err_set(ROAR_ERROR_NOTSUP);
         return -1;
        break;
@@ -741,4 +784,5 @@
        break;
       default:
+        roar_err_set(ROAR_ERROR_NOTSUP);
         return -1;
        break;
@@ -772,4 +816,5 @@
        break;
       default:
+        roar_err_set(ROAR_ERROR_NOTSUP);
         return -1;
        break;
@@ -802,4 +847,5 @@
        break;
       default:
+        roar_err_set(ROAR_ERROR_NOTSUP);
         return -1;
        break;
@@ -831,4 +877,5 @@
        break;
       default:
+        roar_err_set(ROAR_ERROR_NOTSUP);
         return -1;
        break;
@@ -836,4 +883,5 @@
     break;
    default:
+     roar_err_set(ROAR_ERROR_NOTSUP);
      return -1;
     break;
Index: libroar/enumdev.c
===================================================================
--- libroar/enumdev.c	(revision 5138)
+++ libroar/enumdev.c	(revision 5145)
@@ -337,6 +337,8 @@
  int i;
 
- if ( servs == NULL )
-  return -1;
+ if ( servs == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  return -1;
+ }
 
  for (i = 0; (c = &(servs[i]))->server != NULL; i++) {
@@ -361,6 +363,8 @@
  size_t ret;
 
- if ( servs == NULL )
-  return -1;
+ if ( servs == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  return -1;
+ }
 
  for (ret = 0; servs[ret].server != NULL; ret++);
Index: libroar/keyval.c
===================================================================
--- libroar/keyval.c	(revision 4708)
+++ libroar/keyval.c	(revision 5145)
@@ -40,4 +40,9 @@
  ssize_t i;
 
+ if ( kv == NULL || key == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  return NULL;
+ }
+
  if ( casesens )
   sc = strcmp;
@@ -48,4 +53,5 @@
  }
 
+ roar_err_set(ROAR_ERROR_NOENT);
  return NULL;
 }
@@ -67,10 +73,14 @@
  int last_was_seg = 0;
 
- if ( kv == NULL || str == NULL )
+ if ( kv == NULL || str == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
   return -1;
+ }
 
  // we currently do not support quotes
- if ( quotes )
+ if ( quotes ) {
+  roar_err_set(ROAR_ERROR_NOTSUP);
   return -1;
+ }
 
  if ( fdel == NULL )
Index: libroar/ltm.c
===================================================================
--- libroar/ltm.c	(revision 4873)
+++ libroar/ltm.c	(revision 5145)
@@ -65,6 +65,11 @@
  size_t i;
 
- if ( mt == 0 || streams == NULL || slen == 0 || mes == NULL || buf == NULL ) {
+ if ( mt == 0 ) {
   roar_err_set(ROAR_ERROR_INVAL);
+  return -1;
+ }
+
+ if ( streams == NULL || slen == 0 || mes == NULL || buf == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
   return -1;
  }
@@ -172,9 +177,13 @@
  int    i;
 
- if ( con == NULL )
-  return NULL;
-
- if ( streams == NULL || slen == 0 )
-  return NULL;
+ if ( con == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  return NULL;
+ }
+
+ if ( streams == NULL || slen == 0 ) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  return NULL;
+ }
 
  if ( roar_ltm_pack_req(mt, window, streams, slen, &mes, &buf, ROAR_LTM_SST_GET_RAW) == -1 )
@@ -238,6 +247,6 @@
 }
 
-#define _CKNULL(x) if ( (x) == NULL ) return -1
-#define _RETMEMBERCKED(x,m) _CKNULL(x); return (x)->m
+#define _CKNULL(x) if ( (x) == NULL ) { roar_err_set(ROAR_ERROR_FAULT); return -1; }
+#define _RETMEMBERCKED(x,m) _CKNULL(x) return (x)->m
 
 int roar_ltm_get_numstreams(struct roar_ltm_result * res) {
@@ -258,6 +267,8 @@
  ROAR_DBG("roar_ltm_get_streamptr(res=%p, streamidx=%i) = ?", res, streamidx);
 
- if ( res == NULL || streamidx < 0 || streamidx >= res->streams )
-  return NULL;
+ if ( res == NULL || streamidx < 0 || streamidx >= res->streams ) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  return NULL;
+ }
 
  ptr = res->data;
@@ -294,6 +305,8 @@
  ROAR_DBG("roar_ltm_extract(res=%p, mt=0x%.4x, streamidx=%i, channel=%i) = ?", res, mt, streamidx, channel);
 
- if ( roar_ltm_numbits(mt) != 1 )
-  return -1;
+ if ( roar_ltm_numbits(mt) != 1 ) {
+  roar_err_set(ROAR_ERROR_INVAL);
+  return -1;
+ }
 
  ROAR_DBG("roar_ltm_extract(res=%p, mt=0x%.4x, streamidx=%i, channel=%i) = ?", res, mt, streamidx, channel);
@@ -306,6 +319,8 @@
  ROAR_DBG("roar_ltm_extract(res=%p, mt=0x%.4x, streamidx=%i, channel=%i): numchans=%i", res, mt, streamidx, channel, numchans);
 
- if ( channel >= numchans )
-  return -1;
+ if ( channel >= numchans ) {
+  roar_err_set(ROAR_ERROR_RANGE);
+  return -1;
+ }
 
  ptr++;
Index: libroar/stream.c
===================================================================
--- libroar/stream.c	(revision 5072)
+++ libroar/stream.c	(revision 5145)
@@ -85,6 +85,8 @@
                      unsigned int channels, unsigned int bits, unsigned int codec) {
 
- if ( s == NULL )
-  return -1;
+ if ( s == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  return -1;
+ }
 
  s->fh         = -1;
@@ -115,6 +117,8 @@
 
 int roar_stream_set_rel_id(struct roar_stream * s, int id) {
- if ( s == NULL )
-  return -1;
+ if ( s == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  return -1;
+ }
 
  s->pos_rel_id = id;
@@ -124,6 +128,8 @@
 
 int roar_stream_get_rel_id(struct roar_stream * s) {
- if ( s == NULL )
-  return -1;
+ if ( s == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  return -1;
+ }
 
  return s->pos_rel_id;
@@ -131,6 +137,8 @@
 
 int roar_stream_new_by_id(struct roar_stream * s, int id) {
- if ( s == NULL )
-  return -1;
+ if ( s == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  return -1;
+ }
 
  if ( roar_stream_new_empty(s) == -1 )
@@ -141,6 +149,8 @@
 
 int roar_stream_new_empty(struct roar_stream * s) {
- if ( s == NULL )
-  return -1;
+ if ( s == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  return -1;
+ }
 
  return roar_stream_new(s, 0, 0, 0, 0);
@@ -148,6 +158,8 @@
 
 int roar_stream_set_id (struct roar_stream * s, int id) {
- if ( s == NULL )
-  return -1;
+ if ( s == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  return -1;
+ }
 
  s->id = id;
@@ -157,6 +169,8 @@
 
 int roar_stream_get_id (struct roar_stream * s) {
- if ( s == NULL )
-  return -1;
+ if ( s == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  return -1;
+ }
 
  return s->id;
@@ -164,6 +178,8 @@
 
 int roar_stream_set_fh (struct roar_stream * s, int fh) {
- if ( s == NULL )
-  return -1;
+ if ( s == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  return -1;
+ }
 
  s->fh = fh;
@@ -173,6 +189,8 @@
 
 int roar_stream_get_fh (struct roar_stream * s) {
- if ( s == NULL )
-  return -1;
+ if ( s == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  return -1;
+ }
 
  return s->fh;
@@ -180,6 +198,8 @@
 
 int roar_stream_set_dir (struct roar_stream * s, int dir) {
- if ( s == NULL )
-  return -1;
+ if ( s == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  return -1;
+ }
 
  s->dir = dir;
@@ -189,6 +209,8 @@
 
 int roar_stream_get_dir (struct roar_stream * s) {
- if ( s == NULL )
-  return -1;
+ if ( s == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  return -1;
+ }
 
  return s->dir;
@@ -232,6 +254,8 @@
  int len = 0;
 
- if ( host == NULL )
-  return -1;
+ if ( host == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  return -1;
+ }
 
  ROAR_DBG("roar_stream_connect_to_ask(*): Ask the server to connect to: %s:%i", host, port);
@@ -249,6 +273,8 @@
  len = strlen(host);
 
- if ( len > 76 )
-  return -1;
+ if ( len > 76 ) {
+  roar_err_set(ROAR_ERROR_NAMETOOLONG);
+  return -1;
+ }
 
  strncpy(&(m.data[4]), host, len);
@@ -265,4 +291,14 @@
  struct roar_message m;
  int confh;
+
+ if ( con == NULL || s == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  return -1;
+ }
+
+ if ( fh < 0 ) {
+  roar_err_set(ROAR_ERROR_INVAL);
+  return -1;
+ }
 
  memset(&m,  0, sizeof(m));
@@ -310,4 +346,14 @@
  int i;
 
+ if ( con == NULL || s == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  return -1;
+ }
+
+ if ( client < 0 ) {
+  roar_err_set(ROAR_ERROR_INVAL);
+  return -1;
+ }
+
  memset(&m,  0, sizeof(m));
 
@@ -337,4 +383,9 @@
  struct roar_message m;
 
+ if ( con == NULL || s == NULL || data == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  return -1;
+ }
+
  memset(&m,  0, sizeof(m));
 
@@ -361,10 +412,14 @@
  roar_debug_warn_obsolete("roar_stream_send_data", "roar_vio_write", NULL);
 
- if ( s == NULL )
-  return -1;
+ if ( s == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  return -1;
+ }
 
  if ( s->fh == -1 ) {
-  if ( con == NULL )
+  if ( con == NULL ) {
+   roar_err_set(ROAR_ERROR_NOTSUP);
    return -1;
+  }
 
   if ( roar_stream_add_data(con, s, data, len) == -1 )
@@ -375,7 +430,8 @@
 
 #ifdef ROAR_HAVE_IO_POSIX
- return write(s->fh, data, len);
+ return ROAR_NETWORK_WRITE(s->fh, data, len);
 #endif
 
+ roar_err_set(ROAR_ERROR_NOTSUP);
  return -1;
 }
@@ -385,4 +441,9 @@
  uint16_t * data = (uint16_t *) m.data;
  int i;
+
+ if ( con == NULL || s == NULL || info == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  return -1;
+ }
 
  memset(&m,  0, sizeof(m));
@@ -410,9 +471,13 @@
  }
 
- if ( m.datalen < 7*2 )
-  return -1;
-
- if ( data[0] != 0 || data[1] != 1 )
-  return -1;
+ if ( m.datalen < 7*2 ) {
+  roar_err_set(ROAR_ERROR_MSGSIZE);
+  return -1;
+ }
+
+ if ( data[0] != 0 || data[1] != 1 ) {
+  roar_err_set(ROAR_ERROR_NSVERSION);
+  return -1;
+ }
 
  memset(info, 0, sizeof(struct roar_stream_info));
@@ -459,6 +524,8 @@
  uint16_t * data = (uint16_t *) m.data;
 
- if ( con == NULL || s == NULL || name == NULL || len == 0 )
-  return -1;
+ if ( con == NULL || s == NULL || name == NULL || len == 0 ) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  return -1;
+ }
 
  name[0] = 0; // just in case...
@@ -489,6 +556,8 @@
  ROAR_DBG("roar_stream_get_name(*) = ?");
 
- if ( m.datalen < 4 )
-  return -1;
+ if ( m.datalen < 4 ) {
+  roar_err_set(ROAR_ERROR_MSGSIZE);
+  return -1;
+ }
 
  data[0] = ROAR_NET2HOST16(data[0]);
@@ -497,6 +566,13 @@
  ROAR_DBG("roar_stream_get_name(*) = ?");
 
- if ( data[0] != 0 || data[1] != ROAR_STREAM_PARA_NAME )
-  return -1;
+ if ( data[0] != 0 ) {
+  roar_err_set(ROAR_ERROR_NSVERSION);
+  return -1;
+ }
+
+ if ( data[1] != ROAR_STREAM_PARA_NAME ) {
+  roar_err_set(ROAR_ERROR_TYPEMM);
+  return -1;
+ }
 
  m.datalen -= 4;
@@ -521,9 +597,13 @@
  ROAR_DBG("roar_stream_get_chanmap(con=%p, s=%p, map=%p, len=%p) = ?", con, s, map, len);
 
- if ( con == NULL || s == NULL || map == NULL || len == NULL )
-  return -1;
-
- if ( *len == 0 )
-  return -1;
+ if ( con == NULL || s == NULL || map == NULL || len == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  return -1;
+ }
+
+ if ( *len == 0 ) {
+  roar_err_set(ROAR_ERROR_INVAL);
+  return -1;
+ }
 
  memset(&m, 0, sizeof(m));
@@ -549,6 +629,8 @@
  ROAR_DBG("roar_stream_get_chanmap(con=%p, s=%p{.id=%i}, map=%p, len=%p) = ?", con, s, s->id, map, len);
 
- if ( m.datalen < 4 )
-  return -1;
+ if ( m.datalen < 4 ) {
+  roar_err_set(ROAR_ERROR_MSGSIZE);
+  return -1;
+ }
 
  data[0] = ROAR_NET2HOST16(data[0]);
@@ -557,6 +639,13 @@
  ROAR_DBG("roar_stream_get_chanmap(con=%p, s=%p{.id=%i}, map=%p, len=%p) = ?", con, s, s->id, map, len);
 
- if ( data[0] != 0 || data[1] != ROAR_STREAM_PARA_CHANMAP )
-  return -1;
+ if ( data[0] != 0 ) {
+  roar_err_set(ROAR_ERROR_NSVERSION);
+  return -1;
+ }
+
+ if ( data[1] != ROAR_STREAM_PARA_CHANMAP ) {
+  roar_err_set(ROAR_ERROR_TYPEMM);
+  return -1;
+ }
 
  ROAR_DBG("roar_stream_get_chanmap(con=%p, s=%p{.id=%i}, map=%p, len=%p) = ?", con, s, s->id, map, len);
@@ -564,6 +653,8 @@
  m.datalen -= 4;
 
- if ( m.datalen > *len )
-  return -1;
+ if ( m.datalen > *len ) {
+  roar_err_set(ROAR_ERROR_NOMEM);
+  return -1;
+ }
 
  ROAR_DBG("roar_stream_get_chanmap(con=%p, s=%p{.id=%i}, map=%p, len=%p) = ?", con, s, s->id, map, len);
@@ -581,9 +672,13 @@
  uint16_t * data = (uint16_t *) m.data;
 
- if ( con == NULL || s == NULL || map == NULL )
-  return -1;
-
- if ( len == 0 )
+ if ( con == NULL || s == NULL || map == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  return -1;
+ }
+
+ if ( len == 0 ) {
+  roar_err_set(ROAR_ERROR_INVAL);
   return 0;
+ }
 
  memset(&m, 0, sizeof(m));
@@ -622,4 +717,9 @@
  uint16_t * data = (uint16_t *) m.data;
  int i;
+
+ if ( con == NULL || s == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  return -1;
+ }
 
  memset(&m,  0, sizeof(m));
@@ -662,4 +762,9 @@
  int i;
 
+ if ( con == NULL || s == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  return -1;
+ }
+
  memset(&m,  0, sizeof(m));
 
@@ -692,6 +797,8 @@
  int i;
 
- if ( !(s && m) )
-  return -1;
+ if ( s == NULL || m == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  return -1;
+ }
 
  m->datalen = _ROAR_STREAM_MESSAGE_LEN;
@@ -719,9 +826,13 @@
  int i;
 
- if ( !(s && m) )
-  return -1;
-
- if ( m->datalen != _ROAR_STREAM_MESSAGE_LEN )
-  return -1;
+ if ( s == NULL || m == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  return -1;
+ }
+
+ if ( m->datalen != _ROAR_STREAM_MESSAGE_LEN ) {
+  roar_err_set(ROAR_ERROR_MSGSIZE);
+  return -1;
+ }
 
  s->pos = m->pos;
@@ -925,11 +1036,9 @@
   return guess;
 
- if ( codec == NULL || *codec == 0 )
-  return ROAR_CODEC_DEFAULT;
-
  for (i = 0; _libroar_codec[i].codec != -1; i++)
   if ( strcasecmp(_libroar_codec[i].name, codec) == 0 )
    return _libroar_codec[i].codec;
 
+ roar_err_set(ROAR_ERROR_NOENT);
  return -1;
 }
@@ -949,6 +1058,13 @@
  int i;
 
- if ( mime == NULL || *mime == 0 )
-  return -1;
+ if ( mime == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  return -1;
+ }
+
+ if ( *mime == 0 ) {
+  roar_err_set(ROAR_ERROR_INVAL);
+  return -1;
+ }
 
  for (i = 0; _libroar_codec[i].codec != -1; i++)
@@ -957,4 +1073,5 @@
     return _libroar_codec[i].codec;
 
+ roar_err_set(ROAR_ERROR_NOENT);
  return -1;
 }
@@ -967,4 +1084,5 @@
    return _libroar_codec[i].mime;
 
+ roar_err_set(ROAR_ERROR_NOENT);
  return NULL;
 }
@@ -981,4 +1099,5 @@
 
  if ( ret == 0 && rate[0] != '0' ) {
+  roar_err_set(ROAR_ERROR_NOENT);
   return -1;
  }
@@ -998,4 +1117,5 @@
 
  if ( ret == 0 && bits[0] != '0' ) {
+  roar_err_set(ROAR_ERROR_NOENT);
   return -1;
  }
@@ -1021,4 +1141,5 @@
 
  if ( ret == 0 && channels[0] != '0' ) {
+  roar_err_set(ROAR_ERROR_NOENT);
   return -1;
  }
@@ -1065,8 +1186,11 @@
  int i;
 
+ roar_err_clear();
+
  for (i = 0; _libroar_role[i].name != NULL; i++)
   if ( !strcasecmp(_libroar_role[i].name, role) )
    return _libroar_role[i].role;
 
+ roar_err_set(ROAR_ERROR_NOENT);
  return ROAR_ROLE_UNKNOWN;
 }
