Mercurial > hg > freeDiameter
comparison libfdproto/messages.c @ 1027:0117a7746b21
Fix a number of errors and warnings introduced/highlighted by recent commits
author | Sebastien Decugis <sdecugis@freediameter.net> |
---|---|
date | Mon, 15 Apr 2013 15:17:07 +0800 |
parents | 908ffbb81f60 |
children | aecdc2fbf222 |
comparison
equal
deleted
inserted
replaced
1026:beb375690453 | 1027:0117a7746b21 |
---|---|
1514 } | 1514 } |
1515 | 1515 |
1516 /* Write a message header in the buffer */ | 1516 /* Write a message header in the buffer */ |
1517 static int bufferize_msg(unsigned char * buffer, size_t buflen, size_t * offset, struct msg * msg) | 1517 static int bufferize_msg(unsigned char * buffer, size_t buflen, size_t * offset, struct msg * msg) |
1518 { | 1518 { |
1519 TRACE_ENTRY("%p %d %p %p", buffer, buflen, offset, msg); | 1519 TRACE_ENTRY("%p %zd %p %p", buffer, buflen, offset, msg); |
1520 | 1520 |
1521 if ((buflen - *offset) < GETMSGHDRSZ()) | 1521 if ((buflen - *offset) < GETMSGHDRSZ()) |
1522 return ENOSPC; | 1522 return ENOSPC; |
1523 | 1523 |
1524 if (*offset & 0x3) | 1524 if (*offset & 0x3) |
1549 /* Write an AVP in the buffer */ | 1549 /* Write an AVP in the buffer */ |
1550 static int bufferize_avp(unsigned char * buffer, size_t buflen, size_t * offset, struct avp * avp) | 1550 static int bufferize_avp(unsigned char * buffer, size_t buflen, size_t * offset, struct avp * avp) |
1551 { | 1551 { |
1552 struct dict_avp_data dictdata; | 1552 struct dict_avp_data dictdata; |
1553 | 1553 |
1554 TRACE_ENTRY("%p %d %p %p", buffer, buflen, offset, avp); | 1554 TRACE_ENTRY("%p %zd %p %p", buffer, buflen, offset, avp); |
1555 | 1555 |
1556 if ((buflen - *offset) < avp->avp_public.avp_len) | 1556 if ((buflen - *offset) < avp->avp_public.avp_len) |
1557 return ENOSPC; | 1557 return ENOSPC; |
1558 | 1558 |
1559 /* Write the header */ | 1559 /* Write the header */ |
1646 /* Write a chain of AVPs in the buffer */ | 1646 /* Write a chain of AVPs in the buffer */ |
1647 static int bufferize_chain(unsigned char * buffer, size_t buflen, size_t * offset, struct fd_list * list) | 1647 static int bufferize_chain(unsigned char * buffer, size_t buflen, size_t * offset, struct fd_list * list) |
1648 { | 1648 { |
1649 struct fd_list * avpch; | 1649 struct fd_list * avpch; |
1650 | 1650 |
1651 TRACE_ENTRY("%p %d %p %p", buffer, buflen, offset, list); | 1651 TRACE_ENTRY("%p %zd %p %p", buffer, buflen, offset, list); |
1652 | 1652 |
1653 for (avpch = list->next; avpch != list; avpch = avpch->next) { | 1653 for (avpch = list->next; avpch != list; avpch = avpch->next) { |
1654 /* Bufferize the AVP */ | 1654 /* Bufferize the AVP */ |
1655 CHECK_FCT( bufferize_avp(buffer, buflen, offset, _A(avpch->o)) ); | 1655 CHECK_FCT( bufferize_avp(buffer, buflen, offset, _A(avpch->o)) ); |
1656 } | 1656 } |
1709 /* Parse a buffer containing a supposed list of AVPs */ | 1709 /* Parse a buffer containing a supposed list of AVPs */ |
1710 static int parsebuf_list(unsigned char * buf, size_t buflen, struct fd_list * head) | 1710 static int parsebuf_list(unsigned char * buf, size_t buflen, struct fd_list * head) |
1711 { | 1711 { |
1712 size_t offset = 0; | 1712 size_t offset = 0; |
1713 | 1713 |
1714 TRACE_ENTRY("%p %d %p", buf, buflen, head); | 1714 TRACE_ENTRY("%p %zd %p", buf, buflen, head); |
1715 | 1715 |
1716 while (offset < buflen) { | 1716 while (offset < buflen) { |
1717 struct avp * avp; | 1717 struct avp * avp; |
1718 | 1718 |
1719 if (buflen - offset < AVPHDRSZ_NOVEND) { | 1719 if (buflen - offset < AVPHDRSZ_NOVEND) { |
1720 TRACE_DEBUG(INFO, "truncated buffer: remaining only %d bytes", buflen - offset); | 1720 TRACE_DEBUG(INFO, "truncated buffer: remaining only %zd bytes", buflen - offset); |
1721 return EBADMSG; | 1721 return EBADMSG; |
1722 } | 1722 } |
1723 | 1723 |
1724 /* Create a new AVP object */ | 1724 /* Create a new AVP object */ |
1725 CHECK_MALLOC( avp = malloc (sizeof(struct avp)) ); | 1725 CHECK_MALLOC( avp = malloc (sizeof(struct avp)) ); |
1733 | 1733 |
1734 offset += 8; | 1734 offset += 8; |
1735 | 1735 |
1736 if (avp->avp_public.avp_flags & AVP_FLAG_VENDOR) { | 1736 if (avp->avp_public.avp_flags & AVP_FLAG_VENDOR) { |
1737 if (buflen - offset < 4) { | 1737 if (buflen - offset < 4) { |
1738 TRACE_DEBUG(INFO, "truncated buffer: remaining only %d bytes for vendor and data", buflen - offset); | 1738 TRACE_DEBUG(INFO, "truncated buffer: remaining only %zd bytes for vendor and data", buflen - offset); |
1739 free(avp); | 1739 free(avp); |
1740 return EBADMSG; | 1740 return EBADMSG; |
1741 } | 1741 } |
1742 avp->avp_public.avp_vendor = ntohl(*(uint32_t *)(buf + offset)); | 1742 avp->avp_public.avp_vendor = ntohl(*(uint32_t *)(buf + offset)); |
1743 offset += 4; | 1743 offset += 4; |
1744 } | 1744 } |
1745 | 1745 |
1746 /* Check there is enough remaining data in the buffer */ | 1746 /* Check there is enough remaining data in the buffer */ |
1747 if ( (avp->avp_public.avp_len > GETAVPHDRSZ(avp->avp_public.avp_flags)) | 1747 if ( (avp->avp_public.avp_len > GETAVPHDRSZ(avp->avp_public.avp_flags)) |
1748 && (buflen - offset < avp->avp_public.avp_len - GETAVPHDRSZ(avp->avp_public.avp_flags))) { | 1748 && (buflen - offset < avp->avp_public.avp_len - GETAVPHDRSZ(avp->avp_public.avp_flags))) { |
1749 TRACE_DEBUG(INFO, "truncated buffer: remaining only %d bytes for data, and avp data size is %d", | 1749 TRACE_DEBUG(INFO, "truncated buffer: remaining only %zd bytes for data, and avp data size is %d", |
1750 buflen - offset, | 1750 buflen - offset, |
1751 avp->avp_public.avp_len - GETAVPHDRSZ(avp->avp_public.avp_flags)); | 1751 avp->avp_public.avp_len - GETAVPHDRSZ(avp->avp_public.avp_flags)); |
1752 free(avp); | 1752 free(avp); |
1753 return EBADMSG; | 1753 return EBADMSG; |
1754 } | 1754 } |
1772 struct msg * new = NULL; | 1772 struct msg * new = NULL; |
1773 int ret = 0; | 1773 int ret = 0; |
1774 uint32_t msglen = 0; | 1774 uint32_t msglen = 0; |
1775 unsigned char * buf; | 1775 unsigned char * buf; |
1776 | 1776 |
1777 TRACE_ENTRY("%p %d %p", buffer, buflen, msg); | 1777 TRACE_ENTRY("%p %zd %p", buffer, buflen, msg); |
1778 | 1778 |
1779 CHECK_PARAMS( buffer && *buffer && msg && (buflen >= GETMSGHDRSZ()) ); | 1779 CHECK_PARAMS( buffer && *buffer && msg && (buflen >= GETMSGHDRSZ()) ); |
1780 buf = *buffer; | 1780 buf = *buffer; |
1781 *buffer = NULL; | 1781 *buffer = NULL; |
1782 | 1782 |
1786 return EBADMSG; | 1786 return EBADMSG; |
1787 } | 1787 } |
1788 | 1788 |
1789 msglen = ntohl(*(uint32_t *)buf) & 0x00ffffff; | 1789 msglen = ntohl(*(uint32_t *)buf) & 0x00ffffff; |
1790 if ( buflen < msglen ) { | 1790 if ( buflen < msglen ) { |
1791 TRACE_DEBUG(INFO, "Truncated message (%d / %d)", buflen, msglen ); | 1791 TRACE_DEBUG(INFO, "Truncated message (%zd / %d)", buflen, msglen ); |
1792 free(buf); | 1792 free(buf); |
1793 return EBADMSG; | 1793 return EBADMSG; |
1794 } | 1794 } |
1795 | 1795 |
1796 /* Create a new object */ | 1796 /* Create a new object */ |