All of lore.kernel.org
 help / color / mirror / Atom feed
From: Prasanth R <ragaprasanth@gmail.com>
To: u-boot@lists.u-boot-project.org
Cc: Jerome Forissier <jerome.forissier@arm.com>,
	Tom Rini <trini@konsulko.com>,
	Prasanth R <ragaprasanth@gmail.com>
Subject: [PATCH] net: dns: check the A record length before copying the address
Date: Wed,  2 Dec 2026 16:00:46 +0900	[thread overview]
Message-ID: <20261202070046.3548590-1-ragaprasanth@gmail.com> (raw)

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


                 reply	other threads:[~2026-12-02 13:30 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261202070046.3548590-1-ragaprasanth@gmail.com \
    --to=ragaprasanth@gmail.com \
    --cc=jerome.forissier@arm.com \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.u-boot-project.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.