All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] net: dns: check the A record length before copying the address
@ 2026-12-02  7:00 Prasanth R
  0 siblings, 0 replies; only message in thread
From: Prasanth R @ 2026-12-02  7:00 UTC (permalink / raw)
  To: u-boot; +Cc: Jerome Forissier, Tom Rini, Prasanth R

dns_handler() copies 4 bytes of the address before it checks the
record length, and the check uses the length from the packet. An A
record with length 0 at the end of the reply makes it read 3 bytes
past the packet and print, and store in the env, a wrong address.

Copy the address only if the record length is 4 and the 4 bytes are
in the packet.

Fixes: 1a32bf41881b ("Add DNS support")
Signed-off-by: Prasanth R <prasanth.r@lineo.co.jp>
---
I used an AI assistant (Claude) to find this and to write the test.

 net/dns.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/net/dns.c b/net/dns.c
index 08ad54a0..088a35c8 100644
--- a/net/dns.c
+++ b/net/dns.c
@@ -188,9 +188,8 @@ static void dns_handler(uchar *pkt, unsigned dest, struct in_addr sip,
 	if (found && &p[12] < e) {
 		dlen = get_unaligned_be16(p+10);
 		p += 12;
-		memcpy(&ip_addr, p, 4);
-
-		if (p + dlen <= e) {
+		if (dlen == 4 && p + 4 <= e) {
+			memcpy(&ip_addr, p, 4);
 			ip_to_string(ip_addr, ip_str);
 			printf("%s\n", ip_str);
 			if (net_dns_env_var)
-- 
2.34.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-12-02 13:30 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02  7:00 [PATCH] net: dns: check the A record length before copying the address Prasanth R

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.