U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Vivek Ray <vk092kumar@gmail.com>
To: u-boot@lists.denx.de
Cc: casey.connolly@linaro.org, neil.armstrong@linaro.org,
	trini@konsulko.com, u-boot-qcom@groups.io,
	Vivek Ray <vk092kumar@gmail.com>
Subject: [PATCH v2] arm: mach-snapdragon: increase compat buffer size and warn on root compatible string truncation
Date: Wed, 10 Jun 2026 19:24:40 +0530	[thread overview]
Message-ID: <20260610135440.1589268-1-vk092kumar@gmail.com> (raw)
In-Reply-To: <20260610093726.1231041-1-vk092kumar@gmail.com>

The configure_env() function copies root compatible strings into a
32-byte buffer prior to parsing. If a compatible string exceeds this
limit, strlcpy() silently truncates it, producing a malformed fdtfile
path and a silent boot failure with no indication of the root cause.

Bump buf[] to 128 bytes and dt_path[] to 256 bytes to accommodate longer
compatible strings. Also, add explicit truncation checks after both
strlcpy() calls and emit a log_warning() with the offending compatible
string to make such failures easier to diagnose.

Signed-off-by: Vivek Ray <vk092kumar@gmail.com>

---

Changes in V2:
- Bump buf[] from 32 to 128 bytes and dt_path[] from 64 to 256 (Casey Connolly)
- Fix line size check, use > not >= (Casey Connolly)

---
 arch/arm/mach-snapdragon/board.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/arch/arm/mach-snapdragon/board.c b/arch/arm/mach-snapdragon/board.c
index 829a0109ac7..d9390d9b5d3 100644
--- a/arch/arm/mach-snapdragon/board.c
+++ b/arch/arm/mach-snapdragon/board.c
@@ -390,13 +390,14 @@ static void configure_env(void)
 {
 	const char *first_compat, *last_compat;
 	char *tmp;
-	char buf[32] = { 0 };
+	char buf[128] = { 0 };
+	int len = 0;
 	/*
 	 * Most DTB filenames follow the scheme: qcom/<soc>-[vendor]-<board>.dtb
 	 * The vendor is skipped when it's a Qualcomm reference board, or the
 	 * db845c.
 	 */
-	char dt_path[64] = { 0 };
+	char dt_path[256] = { 0 };
 	int compat_count, ret;
 	ofnode root;
 
@@ -417,7 +418,11 @@ static void configure_env(void)
 		return;
 	}
 
-	strlcpy(buf, first_compat, sizeof(buf) - 1);
+	/* A safety check to avoid silent failure due to name truncation */
+	len = strlcpy(buf, first_compat, sizeof(buf) - 1);
+	if (len > sizeof(buf) - 1)
+		log_warning("compatible '%s' got truncated, fdtfile name too long\n",
+			    first_compat);
 	tmp = buf;
 
 	/* The Qualcomm reference boards (RBx, HDK, etc)  */
@@ -468,7 +473,12 @@ static void configure_env(void)
 
 		/* Copy the last compat (e.g. "qcom,sdm845") into buf */
 		memset(buf, 0, sizeof(buf));
-		strlcpy(buf, last_compat, sizeof(buf) - 1);
+
+		/* check for name truncation */
+		len = strlcpy(buf, last_compat, sizeof(buf) - 1);
+		if (len > sizeof(buf) - 1)
+			log_warning("compatible '%s' got truncated, fdtfile name too long\n",
+				    last_compat);
 		tmp = buf;
 
 		/* strsep() is destructive, it replaces the comma with a \0 */
-- 
2.34.1


  parent reply	other threads:[~2026-06-11  2:54 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-10  9:37 [PATCH] arm: mach-snapdragon: warn on root compatible string truncation Vivek Ray
2026-06-10 11:27 ` Casey Connolly
2026-06-10 13:54 ` Vivek Ray [this message]
2026-06-17  6:27   ` [PATCH v2] arm: mach-snapdragon: increase compat buffer size and " Vivek Ray
2026-06-17 14:56   ` Casey Connolly

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=20260610135440.1589268-1-vk092kumar@gmail.com \
    --to=vk092kumar@gmail.com \
    --cc=casey.connolly@linaro.org \
    --cc=neil.armstrong@linaro.org \
    --cc=trini@konsulko.com \
    --cc=u-boot-qcom@groups.io \
    --cc=u-boot@lists.denx.de \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox