Ver código fonte

seas: safety check for target buffer size before copying message in encode_msg()

- avoid buffer overflow for large SIP messages
- reported by Stelios Tsampas
Daniel-Constantin Mierla 9 anos atrás
pai
commit
f50c9c853e
1 arquivos alterados com 6 adições e 0 exclusões
  1. 6 0
      modules/seas/encode_msg.c

+ 6 - 0
modules/seas/encode_msg.c

@@ -158,6 +158,7 @@ int encode_msg(struct sip_msg *msg,char *payload,int len)
 
 
    if(len < MAX_ENCODED_MSG + MAX_MESSAGE_LEN)
    if(len < MAX_ENCODED_MSG + MAX_MESSAGE_LEN)
       return -1;
       return -1;
+
    if(parse_headers(msg,HDR_EOH_F,0)<0){
    if(parse_headers(msg,HDR_EOH_F,0)<0){
       myerror="in parse_headers";
       myerror="in parse_headers";
       goto error;
       goto error;
@@ -266,6 +267,11 @@ int encode_msg(struct sip_msg *msg,char *payload,int len)
    /*j+=k;*/
    /*j+=k;*/
    /*pkg_free(payload2);*/
    /*pkg_free(payload2);*/
    /*now we copy the actual message after the headers-meta-section*/
    /*now we copy the actual message after the headers-meta-section*/
+
+	if(len < j + msg->len + 1) {
+   	   LM_ERR("not enough space to encode sip message\n");
+   	   return -1;
+	}
    memcpy(&payload[j],msg->buf,msg->len);
    memcpy(&payload[j],msg->buf,msg->len);
    LM_DBG("msglen = %d,msg starts at %d\n",msg->len,j);
    LM_DBG("msglen = %d,msg starts at %d\n",msg->len,j);
    j=htons(j);
    j=htons(j);