gnrc_udp: assert ports not zero

UDP port 0 is reserved for system usage, e.g., to tell the OS to
    set a random source port. Hence, neither source nor destination
    port should be 0 when transmitting. This PR adds proper asserts.
This commit is contained in:
smlng 2018-08-06 16:09:22 +02:00
parent 3e7c5423e5
commit fd718dfc74
2 changed files with 4 additions and 0 deletions

View File

@ -76,6 +76,8 @@ int gnrc_udp_calc_csum(gnrc_pktsnip_t *hdr, gnrc_pktsnip_t *pseudo_hdr);
* @return pointer to the newly created (and allocated) header * @return pointer to the newly created (and allocated) header
* @return NULL on `src == NULL`, `dst == NULL`, `src_len != 2`, `dst_len != 2` * @return NULL on `src == NULL`, `dst == NULL`, `src_len != 2`, `dst_len != 2`
* or on allocation error * or on allocation error
*
* @pre `src > 0` and `dst > 0`
*/ */
gnrc_pktsnip_t *gnrc_udp_hdr_build(gnrc_pktsnip_t *payload, uint16_t src, gnrc_pktsnip_t *gnrc_udp_hdr_build(gnrc_pktsnip_t *payload, uint16_t src,
uint16_t dst); uint16_t dst);

View File

@ -280,6 +280,8 @@ int gnrc_udp_calc_csum(gnrc_pktsnip_t *hdr, gnrc_pktsnip_t *pseudo_hdr)
gnrc_pktsnip_t *gnrc_udp_hdr_build(gnrc_pktsnip_t *payload, uint16_t src, gnrc_pktsnip_t *gnrc_udp_hdr_build(gnrc_pktsnip_t *payload, uint16_t src,
uint16_t dst) uint16_t dst)
{ {
assert((src > 0) && (dst > 0));
gnrc_pktsnip_t *res; gnrc_pktsnip_t *res;
udp_hdr_t *hdr; udp_hdr_t *hdr;