# HG changeset patch # User Sebastien Decugis # Date 1231400755 -32400 # Node ID 7e2c809b7892c494e6085e2bc651a46f8c68a267 # Parent a4592b91368c20bac49b043bbd003e09710ec8d3 Fix small error diff -r a4592b91368c -r 7e2c809b7892 waaad/message.c --- a/waaad/message.c Thu Jan 08 15:37:51 2009 +0900 +++ b/waaad/message.c Thu Jan 08 16:45:55 2009 +0900 @@ -741,15 +741,12 @@ static int _msg_buf_avp(unsigned char * buffer, size_t buflen, size_t * offset, _msg_avp_t * avp) { dict_avp_data_t dictdata; - size_t offsetini; TRACE_ENTRY("%p %d %p %p", buffer, buflen, offset, avp); if ((buflen - *offset) < avp->avp_public.avp_len) return ENOSPC; - offsetini = *offset; - /* Write the header */ PUT_in_buf_32(avp->avp_public.avp_code, buffer + *offset); *offset += 4; @@ -771,8 +768,9 @@ if ( avp->avp_source != NULL ) { /* the message was not parsed completely */ - memcpy(&buffer[*offset], avp->avp_source, avp->avp_public.avp_len + offsetini - *offset); - *offset = PAD4(avp->avp_public.avp_len + offsetini); + size_t datalen = avp->avp_public.avp_len - GETAVPHDRSZ(avp->avp_public.avp_flags); + memcpy(&buffer[*offset], avp->avp_source, datalen); + *offset += PAD4(datalen); } else { /* the content is stored in rawdata */ memcpy(&buffer[*offset], avp->avp_rawdata, avp->avp_rawlen); @@ -970,9 +968,11 @@ /* we must copy the data from the source to the internal buffer area */ CHECK_PARAMS( !avp->avp_rawdata ); - CHECK_MALLOC( avp->avp_rawdata = malloc(avp->avp_public.avp_len - GETAVPHDRSZ( avp->avp_public.avp_flags )) ); + avp->avp_rawlen = avp->avp_public.avp_len - GETAVPHDRSZ( avp->avp_public.avp_flags ); - memcpy(avp->avp_rawdata, avp->avp_source, avp->avp_public.avp_len - GETAVPHDRSZ( avp->avp_public.avp_flags )); + CHECK_MALLOC( avp->avp_rawdata = malloc(avp->avp_rawlen) ); + + memcpy(avp->avp_rawdata, avp->avp_source, avp->avp_rawlen); avp->avp_source = NULL; TRACE_DEBUG(FULL, "Unsupported optional AVP found, raw source data saved in avp_rawdata.");