[PATCH 02/10] fs: tftp: use net_eth_to_udp() for packet parsing

Sascha Hauer s.hauer at pengutronix.de
Wed Apr 1 23:36:41 PDT 2026


Replace the separate net_eth_to_udp_payload(), net_eth_to_udphdr() and
net_eth_to_udplen() calls with the new consolidated net_eth_to_udp()
helper.  This validates the packet length before accessing any headers
and removes the need to cast away the unused len parameter.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
Co-Authored-By: Claude Opus 4.6 <noreply at anthropic.com>
---
 fs/tftp.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/fs/tftp.c b/fs/tftp.c
index a454306b4b..fe6f42b073 100644
--- a/fs/tftp.c
+++ b/fs/tftp.c
@@ -628,11 +628,12 @@ static void tftp_recv(struct file_priv *priv,
 static void tftp_handler(void *ctx, char *packet, unsigned len)
 {
 	struct file_priv *priv = ctx;
-	char *pkt = net_eth_to_udp_payload(packet);
-	struct udphdr *udp = net_eth_to_udphdr(packet);
+	struct net_udp_pkt udp;
 
-	(void)len;
-	tftp_recv(priv, pkt, net_eth_to_udplen(packet), udp->uh_sport);
+	if (net_eth_to_udp(packet, len, &udp))
+		return;
+
+	tftp_recv(priv, udp.payload, udp.len, udp.udp->uh_sport);
 }
 
 static int tftp_start_transfer(struct file_priv *priv)

-- 
2.47.3




More information about the barebox mailing list