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;
