gbprox_rx_ptp_from_bss: fix dangling pointer

Building with gcc (Debian 12.2.0-14) 12.2.0 and --enable-werror fails
without this during "make distcheck":

../../../src/gb_proxy.c:450:24: error: storing the address of local variable 'tp' in '((struct libgb_msgb_cb *)msg)[2].bssgp_cell_id' [-Werror=dangling-pointer=]
  450 |         msgb_bcid(msg) = (void *)&tp;

This means that gcc now warns (and we turn that into an error) if one
assigns the address of a local (stack) variable to something allocated
on the heap, and doesn't remove that reference before ending the function
(invalidating the stack).

Related: OS#6057
Change-Id: Ie51e37572993cb5dc24ecf13bc300225f09cb744
This commit is contained in:
Oliver Smith 2023-07-13 13:23:27 +02:00 committed by laforge
parent 7724fb717b
commit c44b50c147
1 changed files with 2 additions and 0 deletions

View File

@ -532,6 +532,8 @@ static int gbprox_rx_ptp_from_bss(struct gbproxy_nse *nse, struct msgb *msg, uin
if (rc < 0)
rate_ctr_inc(rate_ctr_group_get_ctr(bss_bvc->ctrg, GBPROX_PEER_CTR_FWD_FROM_BSS_ERR));
/* avoid a dangling pointer from heap to stack (see above "hack" to set it to &tp) */
msgb_bcid(msg) = 0;
return 0;
}