On Tue, Sep 15, 2026 at 08:18:27AM +0000, Bill Wendling wrote:
When CONFIG_CMDLINE_EXTEND is enabled, early_init_dt_scan_chosen() uses
two strlcat() calls to append a space and CONFIG_CMDLINE to the command
line buffer.
In preparation for removing the deprecated strlcat() API[1], replace the
strlcat() calls with a single snprintf() call using the existing string
length.
Additionally, check for a NULL initial_boot_params pointer and jump to
"handle_cmdline" so that CONFIG_CMDLINE handling still occurs without
dereferencing a NULL FDT pointer in fdt_path_offset().
Link: https://github.com/KSPP/linux/issues/370 [1]
Cc: codemender-patching+linux@google.com
Assisted-by: Assistant:Claude-3.5-Sonnet [editor_update_file, shell_command_run]
Signed-off-by: Bill Wendling <morbo@google.com>
---
quoted hunk ↗ jump to hunk
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index a64afc3ded3d..311021a83f03 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -1095,6 +1095,9 @@ int __init early_init_dt_scan_chosen(char *cmdline)
const void *rng_seed;
const void *fdt = initial_boot_params;
+ if (!fdt)
+ goto handle_cmdline;
+
node = fdt_path_offset(fdt, "/chosen");
if (node < 0)
node = fdt_path_offset(fdt, "/chosen@0");
@@ -1133,8 +1136,12 @@ int __init early_init_dt_scan_chosen(char *cmdline)
*/
#ifdef CONFIG_CMDLINE
#if defined(CONFIG_CMDLINE_EXTEND)
- strlcat(cmdline, " ", COMMAND_LINE_SIZE);
- strlcat(cmdline, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
+ {
No need for brackets.
+ size_t len = strlen(cmdline);
+
+ if (len < COMMAND_LINE_SIZE)
+ snprintf(cmdline + len, COMMAND_LINE_SIZE - len, " %s", CONFIG_CMDLINE);
+ }
#elif defined(CONFIG_CMDLINE_FORCE)
strscpy(cmdline, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
#else
--
2.55.0.1032.g73a4cd73de-goog