Add error verification in netbuff operations.
This commit is contained in:
parent
d6d205568f
commit
d855fbcf37
7 changed files with 38 additions and 19 deletions
|
@ -39,6 +39,7 @@ grub_net_arp_resolve (struct grub_net_network_level_interface *inf,
|
|||
struct arphdr *arp_header;
|
||||
grub_net_link_level_address_t target_hw_addr;
|
||||
char *aux, arp_data[128];
|
||||
grub_err_t err;
|
||||
int i;
|
||||
|
||||
/* Check cache table. */
|
||||
|
@ -52,9 +53,11 @@ grub_net_arp_resolve (struct grub_net_network_level_interface *inf,
|
|||
nb.head = arp_data;
|
||||
nb.end = arp_data + sizeof (arp_data);
|
||||
grub_netbuff_clear (&nb);
|
||||
|
||||
grub_netbuff_reserve (&nb, 128);
|
||||
grub_netbuff_push (&nb, sizeof (*arp_header) + 2 * (6 + 4));
|
||||
|
||||
if ((err = grub_netbuff_push (&nb, sizeof (*arp_header) + 2 * (6 + 4))) != GRUB_ERR_NONE)
|
||||
return err;
|
||||
|
||||
arp_header = (struct arphdr *) nb.data;
|
||||
arp_header->hrd = grub_cpu_to_be16 (GRUB_NET_ARPHRD_ETHERNET);
|
||||
arp_header->pro = grub_cpu_to_be16 (GRUB_NET_ETHERTYPE_IP);
|
||||
|
|
|
@ -228,7 +228,10 @@ GRUB_MOD_FINI(ofnet)
|
|||
struct grub_net_card *card;
|
||||
FOR_NET_CARDS (card)
|
||||
if (card->driver && !grub_strcmp (card->driver->name, "ofnet"))
|
||||
card->driver->fini (card);
|
||||
{
|
||||
card->driver->fini (card);
|
||||
card->driver = NULL;
|
||||
}
|
||||
grub_net_card_driver_unregister (&ofdriver);
|
||||
grub_getbootp = NULL;
|
||||
}
|
||||
|
|
|
@ -15,8 +15,10 @@ send_ethernet_packet (struct grub_net_network_level_interface *inf,
|
|||
grub_uint16_t ethertype)
|
||||
{
|
||||
struct etherhdr *eth;
|
||||
grub_err_t err;
|
||||
|
||||
grub_netbuff_push (nb, sizeof (*eth));
|
||||
if ((err = grub_netbuff_push (nb, sizeof (*eth))) != GRUB_ERR_NONE)
|
||||
return err;
|
||||
eth = (struct etherhdr *) nb->data;
|
||||
grub_memcpy (eth->dst, target_addr.mac, 6);
|
||||
grub_memcpy (eth->src, inf->hwaddress.mac, 6);
|
||||
|
@ -33,10 +35,12 @@ grub_net_recv_ethernet_packet (struct grub_net_buff *nb)
|
|||
struct llchdr *llch;
|
||||
struct snaphdr *snaph;
|
||||
grub_uint16_t type;
|
||||
grub_err_t err;
|
||||
|
||||
eth = (struct etherhdr *) nb->data;
|
||||
type = grub_be_to_cpu16 (eth->type);
|
||||
grub_netbuff_pull (nb, sizeof (*eth));
|
||||
if ((err = grub_netbuff_pull (nb, sizeof (*eth))) != GRUB_ERR_NONE)
|
||||
return err;
|
||||
|
||||
if (type <= 1500)
|
||||
{
|
||||
|
@ -45,7 +49,8 @@ grub_net_recv_ethernet_packet (struct grub_net_buff *nb)
|
|||
|
||||
if (llch->dsap == 0xaa && llch->ssap == 0xaa && llch->ctrl == 0x3)
|
||||
{
|
||||
grub_netbuff_pull (nb, sizeof (*llch));
|
||||
if ((err = grub_netbuff_pull (nb, sizeof (*llch))) != GRUB_ERR_NONE)
|
||||
return err;
|
||||
snaph = (struct snaphdr *) nb->data;
|
||||
type = snaph->type;
|
||||
}
|
||||
|
|
|
@ -85,7 +85,10 @@ grub_err_t
|
|||
grub_net_recv_ip_packets (struct grub_net_buff *nb)
|
||||
{
|
||||
struct iphdr *iph = (struct iphdr *) nb->data;
|
||||
grub_netbuff_pull (nb, sizeof (*iph));
|
||||
grub_err_t err;
|
||||
|
||||
if ((err = grub_netbuff_pull (nb, sizeof (*iph))) != GRUB_ERR_NONE)
|
||||
return err;
|
||||
|
||||
switch (iph->protocol)
|
||||
{
|
||||
|
|
|
@ -95,12 +95,12 @@ grub_err_t
|
|||
grub_netbuff_free (struct grub_net_buff *nb)
|
||||
{
|
||||
grub_free (nb->head);
|
||||
return 0;
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
grub_err_t
|
||||
grub_netbuff_clear (struct grub_net_buff *nb)
|
||||
{
|
||||
nb->data = nb->tail = nb->head;
|
||||
return 0;
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
|
|
@ -34,7 +34,8 @@ tftp_open (struct grub_file *file, const char *filename)
|
|||
grub_netbuff_clear (&nb);
|
||||
|
||||
grub_netbuff_reserve (&nb, 1500);
|
||||
grub_netbuff_push (&nb, sizeof (*tftph));
|
||||
if ((err = grub_netbuff_push (&nb, sizeof (*tftph))) != GRUB_ERR_NONE)
|
||||
return err;
|
||||
|
||||
tftph = (struct tftphdr *) nb.data;
|
||||
|
||||
|
@ -67,8 +68,8 @@ tftp_open (struct grub_file *file, const char *filename)
|
|||
rrq += grub_strlen ("0") + 1;
|
||||
hdrlen = sizeof (tftph->opcode) + rrqlen;
|
||||
|
||||
grub_netbuff_unput (&nb, nb.tail - (nb.data + hdrlen));
|
||||
|
||||
if ((err = grub_netbuff_unput (&nb, nb.tail - (nb.data + hdrlen))) != GRUB_ERR_NONE)
|
||||
return err;
|
||||
file->device->net->socket->out_port = TFTP_SERVER_PORT;
|
||||
|
||||
err = grub_net_send_udp_packet (file->device->net->socket, &nb);
|
||||
|
@ -130,9 +131,9 @@ tftp_receive (grub_net_socket_t sock, struct grub_net_buff *nb)
|
|||
grub_netbuff_clear (nb);
|
||||
break;
|
||||
case TFTP_DATA:
|
||||
grub_netbuff_pull (nb, sizeof (tftph->opcode) +
|
||||
sizeof (tftph->u.data.block));
|
||||
|
||||
if ((err = grub_netbuff_pull (nb, sizeof (tftph->opcode) +
|
||||
sizeof (tftph->u.data.block))) != GRUB_ERR_NONE)
|
||||
return err;
|
||||
if (grub_be_to_cpu16 (tftph->u.data.block) == data->block + 1)
|
||||
{
|
||||
data->block++;
|
||||
|
@ -141,7 +142,8 @@ tftp_receive (grub_net_socket_t sock, struct grub_net_buff *nb)
|
|||
sock->status = 2;
|
||||
/* Prevent garbage in broken cards. */
|
||||
if (size > 1024)
|
||||
grub_netbuff_unput (nb, size - 1024);
|
||||
if ((err = grub_netbuff_unput (nb, size - 1024)) != GRUB_ERR_NONE)
|
||||
return err;
|
||||
}
|
||||
else
|
||||
grub_netbuff_clear (nb);
|
||||
|
@ -154,8 +156,9 @@ tftp_receive (grub_net_socket_t sock, struct grub_net_buff *nb)
|
|||
}
|
||||
grub_netbuff_clear (&nb_ack);
|
||||
grub_netbuff_reserve (&nb_ack, 128);
|
||||
grub_netbuff_push (&nb_ack, sizeof (tftph->opcode)
|
||||
+ sizeof (tftph->u.ack.block));
|
||||
if ((err = grub_netbuff_push (&nb_ack, sizeof (tftph->opcode)
|
||||
+ sizeof (tftph->u.ack.block))) != GRUB_ERR_NONE)
|
||||
return err;
|
||||
|
||||
tftph = (struct tftphdr *) nb_ack.data;
|
||||
tftph->opcode = grub_cpu_to_be16 (TFTP_ACK);
|
||||
|
|
|
@ -9,8 +9,10 @@ grub_net_send_udp_packet (const grub_net_socket_t socket,
|
|||
struct grub_net_buff *nb)
|
||||
{
|
||||
struct udphdr *udph;
|
||||
grub_err_t err;
|
||||
|
||||
grub_netbuff_push (nb, sizeof (*udph));
|
||||
if ((err = grub_netbuff_push (nb, sizeof (*udph))) != GRUB_ERR_NONE)
|
||||
return err;
|
||||
|
||||
udph = (struct udphdr *) nb->data;
|
||||
udph->src = grub_cpu_to_be16 (socket->in_port);
|
||||
|
|
Loading…
Reference in a new issue