structure optimizations again.
[silc.git] / lib / silccore / silcid.c
index 6a7fb8f2c72c38c20902cd95f137045b61b32c00..6e892c087b2a8dedb675bbf4206408873fe48637 100644 (file)
@@ -62,6 +62,9 @@ SilcIDPayload silc_id_payload_parse(const unsigned char *payload,
   if (ret == -1)
     goto err;
 
+  if (newp->type > SILC_ID_CHANNEL)
+    goto err;
+
   silc_buffer_pull(&buffer, 4);
 
   if (newp->len > buffer.len || newp->len > SILC_PACKET_MAX_ID_LEN)
@@ -102,6 +105,9 @@ void *silc_id_payload_parse_id(const unsigned char *data, SilcUInt32 len,
   if (ret == -1)
     return NULL;
 
+  if (type > SILC_ID_CHANNEL)
+    return NULL;
+
   silc_buffer_pull(&buffer, 4);
 
   if (idlen > buffer.len || idlen > SILC_PACKET_MAX_ID_LEN)
@@ -209,6 +215,9 @@ unsigned char *silc_id_id2str(const void *id, SilcIdType type)
   SilcChannelID *channel_id;
   SilcUInt32 id_len = silc_id_get_len(id, type);
 
+  if (id_len > SILC_PACKET_MAX_ID_LEN)
+    return NULL;
+
   switch(type) {
   case SILC_ID_SERVER:
     server_id = (SilcServerID *)id;
@@ -251,6 +260,8 @@ unsigned char *silc_id_id2str(const void *id, SilcIdType type)
 void *silc_id_str2id(const unsigned char *id, SilcUInt32 id_len, 
                     SilcIdType type)
 {
+  if (id_len > SILC_PACKET_MAX_ID_LEN)
+    return NULL;
 
   switch(type) {
   case SILC_ID_SERVER: