From 0696f08f9238087edf5c1f1b91779f7515e7aeb5 Mon Sep 17 00:00:00 2001 From: Manoel Rebelo Abranches Date: Tue, 10 May 2011 14:07:20 -0300 Subject: [PATCH] Prevente error in broken cards by limiting data size. --- grub-core/net/tftp.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/grub-core/net/tftp.c b/grub-core/net/tftp.c index cafb30585..6cc281085 100644 --- a/grub-core/net/tftp.c +++ b/grub-core/net/tftp.c @@ -126,8 +126,12 @@ tftp_receive (grub_net_socket_t sock, struct grub_net_buff *nb) if (grub_be_to_cpu16 (tftph->u.data.block) == data->block + 1) { data->block++; - if (nb->tail - nb->data < 1024) + unsigned size = nb->tail - nb->data; + if (size < 1024) sock->status = 2; + /* Prevent garbage in broken cards. */ + if (size > 1024) + grub_netbuff_unput (nb, size - 1024); } else grub_netbuff_clear(nb);