mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
Merge pull request #4394 from authmillenon/sc_netif/fix/null-pointer-checks
sc_netif: check for NULL pointers on send
This commit is contained in:
commit
0e285e89b0
@ -835,7 +835,7 @@ int _netif_send(int argc, char **argv)
|
|||||||
kernel_pid_t dev;
|
kernel_pid_t dev;
|
||||||
uint8_t addr[MAX_ADDR_LEN];
|
uint8_t addr[MAX_ADDR_LEN];
|
||||||
size_t addr_len;
|
size_t addr_len;
|
||||||
gnrc_pktsnip_t *pkt;
|
gnrc_pktsnip_t *pkt, *hdr;
|
||||||
gnrc_netif_hdr_t *nethdr;
|
gnrc_netif_hdr_t *nethdr;
|
||||||
uint8_t flags = 0x00;
|
uint8_t flags = 0x00;
|
||||||
|
|
||||||
@ -867,15 +867,22 @@ int _netif_send(int argc, char **argv)
|
|||||||
|
|
||||||
/* put packet together */
|
/* put packet together */
|
||||||
pkt = gnrc_pktbuf_add(NULL, argv[3], strlen(argv[3]), GNRC_NETTYPE_UNDEF);
|
pkt = gnrc_pktbuf_add(NULL, argv[3], strlen(argv[3]), GNRC_NETTYPE_UNDEF);
|
||||||
pkt = gnrc_pktbuf_add(pkt, NULL, sizeof(gnrc_netif_hdr_t) + addr_len,
|
if (pkt == NULL) {
|
||||||
GNRC_NETTYPE_NETIF);
|
puts("error: packet buffer full");
|
||||||
nethdr = (gnrc_netif_hdr_t *)pkt->data;
|
return 1;
|
||||||
gnrc_netif_hdr_init(nethdr, 0, addr_len);
|
}
|
||||||
gnrc_netif_hdr_set_dst_addr(nethdr, addr, addr_len);
|
hdr = gnrc_netif_hdr_build(NULL, 0, addr, addr_len);
|
||||||
|
if (hdr == NULL) {
|
||||||
|
puts("error: packet buffer full");
|
||||||
|
gnrc_pktbuf_release(pkt);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
LL_PREPEND(pkt, hdr);
|
||||||
|
nethdr = (gnrc_netif_hdr_t *)hdr->data;
|
||||||
nethdr->flags = flags;
|
nethdr->flags = flags;
|
||||||
/* and send it */
|
/* and send it */
|
||||||
if (gnrc_netapi_send(dev, pkt) < 1) {
|
if (gnrc_netapi_send(dev, pkt) < 1) {
|
||||||
puts("error: unable to send\n");
|
puts("error: unable to send");
|
||||||
gnrc_pktbuf_release(pkt);
|
gnrc_pktbuf_release(pkt);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user