{"id":2225550,"url":"http://patchwork.ozlabs.org/api/patches/2225550/?format=json","web_url":"http://patchwork.ozlabs.org/project/uboot/patch/20260421053511.84312-1-S4210155@student.rmit.edu.au/","project":{"id":18,"url":"http://patchwork.ozlabs.org/api/projects/18/?format=json","name":"U-Boot","link_name":"uboot","list_id":"u-boot.lists.denx.de","list_email":"u-boot@lists.denx.de","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20260421053511.84312-1-S4210155@student.rmit.edu.au>","list_archive_url":null,"date":"2026-04-21T05:35:08","name":"common: cli_hush: fix console_buffer overflow on boot retry","commit_ref":null,"pull_url":null,"state":"changes-requested","archived":false,"hash":"a3e83f67a4c03ca80ad6433f08d81828c8c358c1","submitter":{"id":92995,"url":"http://patchwork.ozlabs.org/api/people/92995/?format=json","name":"Ngo Luong Thanh Tra","email":"ngotra27101996@gmail.com"},"delegate":{"id":3651,"url":"http://patchwork.ozlabs.org/api/users/3651/?format=json","username":"trini","first_name":"Tom","last_name":"Rini","email":"trini@ti.com"},"mbox":"http://patchwork.ozlabs.org/project/uboot/patch/20260421053511.84312-1-S4210155@student.rmit.edu.au/mbox/","series":[{"id":500748,"url":"http://patchwork.ozlabs.org/api/series/500748/?format=json","web_url":"http://patchwork.ozlabs.org/project/uboot/list/?series=500748","date":"2026-04-21T05:35:08","name":"common: cli_hush: fix console_buffer overflow on boot retry","version":1,"mbox":"http://patchwork.ozlabs.org/series/500748/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2225550/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2225550/checks/","tags":{},"related":[],"headers":{"Return-Path":"<u-boot-bounces@lists.denx.de>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256\n header.s=20251104 header.b=XeQO9bAA;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de\n (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de;\n envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org)","phobos.denx.de;\n dmarc=pass (p=none dis=none) header.from=gmail.com","phobos.denx.de;\n spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de","phobos.denx.de;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=gmail.com header.i=@gmail.com header.b=\"XeQO9bAA\";\n\tdkim-atps=neutral","phobos.denx.de;\n dmarc=pass (p=none dis=none) header.from=gmail.com","phobos.denx.de;\n spf=pass smtp.mailfrom=ngotra27101996@gmail.com"],"Received":["from phobos.denx.de (phobos.denx.de\n [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g0DWq4DJ8z1yCv\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 21 Apr 2026 17:29:43 +1000 (AEST)","from h2850616.stratoserver.net (localhost [IPv6:::1])\n\tby phobos.denx.de (Postfix) with ESMTP id 49E1983E36;\n\tTue, 21 Apr 2026 09:29:30 +0200 (CEST)","by phobos.denx.de (Postfix, from userid 109)\n id B73FE83FFA; Tue, 21 Apr 2026 07:35:24 +0200 (CEST)","from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com\n [IPv6:2607:f8b0:4864:20::42c])\n (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits))\n (No client certificate requested)\n by phobos.denx.de (Postfix) with ESMTPS id 46BB083C51\n for <u-boot@lists.denx.de>; Tue, 21 Apr 2026 07:35:21 +0200 (CEST)","by mail-pf1-x42c.google.com with SMTP id\n d2e1a72fcca58-82735a41920so1568385b3a.2\n for <u-boot@lists.denx.de>; Mon, 20 Apr 2026 22:35:21 -0700 (PDT)","from MacBookAir.STASGS.RMIT.EDU.VN ([103.253.89.46])\n by smtp.gmail.com with ESMTPSA id\n d2e1a72fcca58-82f94204ac8sm11476773b3a.0.2026.04.20.22.35.16\n (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256);\n Mon, 20 Apr 2026 22:35:19 -0700 (PDT)"],"X-Spam-Checker-Version":"SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de","X-Spam-Level":"","X-Spam-Status":"No, score=-0.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,\n DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_GMAIL_RCVD,\n FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,RCVD_IN_DNSWL_BLOCKED,\n SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=gmail.com; s=20251104; t=1776749719; x=1777354519; darn=lists.denx.de;\n h=content-transfer-encoding:mime-version:message-id:date:subject:cc\n :to:from:from:to:cc:subject:date:message-id:reply-to;\n bh=14sAsstZjrHVPsX3SJQ2nyvEHfaU34skXxYentPztHI=;\n b=XeQO9bAAu+HMQsgP1wW60iCHo0HejG9B7rP7v6tRXCwC/3LBJVOAdS0op5EndkBXkt\n 7w/PBY5JrACwZg4DHtpXrUeBuvMDmEhhTKgD1YPDNRDUdpjynFjdMm2wokviMobn0fBH\n xIEY2ZVpf692iLsGiM8yxfz0qoSYYUMpN16p5kJxtYM3pXmUrfHBw5VgFGjkWc1CW+OG\n zLF65gIEJeI84o4HZSltmyWCsb1adIu+FpjeRTRp3IiSK7XonQxCKLSTQq1o9s+2YYzt\n sg+rvWPHZsJ2va55r9obxIsLI9pBAAFbRcD4AJlUpGrNd8gljud9aWFw+GZJeB9emN81\n pXwQ==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1776749719; x=1777354519;\n h=content-transfer-encoding:mime-version:message-id:date:subject:cc\n :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date\n :message-id:reply-to;\n bh=14sAsstZjrHVPsX3SJQ2nyvEHfaU34skXxYentPztHI=;\n b=ei42+C+1jg+AEFardvfJfmGu9fEZteb/Igs9FoZcJ8avzwp8yaVGk3VtBi6mQNw6uz\n 7sHhaWRkGGMK5Mb38cEpy/vcjHOzAXyENRwUe0a7NQmEQ94PORX3QQBqW/5qWQl0tADe\n KtB0OvBlBYLwKpyeWWsyw/3+q/SGTRdayTrqtip/ny8VKSWacN7e/0s61IqCwVwqW/xH\n 8izpegBu6c3LvfwZ1eLXNuarS80ikSRhLgrDqAfUkHHMHEfjR9VNk/c1UfSYh7BvLyNT\n mSpOuX1AjAbb6n3o8UhN/Grp/zYNZY8ibAEMF6lNLN7+brBeHCgPYwZ6doUlb3LbUAAj\n huNQ==","X-Gm-Message-State":"AOJu0Yxxc6wgbftJfihIxUUzSnvcFp7DM1Leko3TPHBNXbxOhxh+TKu/\n nPOrxXRtaaKRfcIkqQB1KkhKacH2YcRPtLUUJIkR6BGmiA4KOTkX+k2Dd+9y7yPB","X-Gm-Gg":"AeBDieslu3251fMQWPg1NOHRX4WQfpro8eJHL8yz7m54OzQUazr/zjTO8piVREzhebC\n 9A4f2GCqmV1KcIl6cjxaP7ai0Pd+UxcxnnaN5szVOdJMJPyZ17a7LcfBmnESny7QLzsrwM6E04x\n YW7CSFjq7Mtg2BSNH7vZU41C8ecv8UpRlsiMCZR8Axrct2kRVbeUDCJyEbiDDg90AgSUubH5qLz\n upH7upLN+nrSJs1ehNtmBtM4GtOQCYwOQ8Fm8FhRkauN1TMT8hqu7VIT/K2elcJWrQ1C4s9LfSO\n Nx+3ABHxae4P23mqC1N7TBepjbhOpfHoR22JInkm6baiSmPjFERWEklULJF7HtVk+C6YQgYpX7C\n ZG7hr8IDezrAPBrU2ewR5K8kd3XoO4xiGcegseF7SM1EBEqdCItZejqdsj0GAtrLvM4VZE2RWkJ\n josNgydngyggikK2muCd6eXjgPhzUAaUiJmug+nxFd6P8YLUlztw5tPW75zVTedmeBk0PcfqXLl\n dclbymEc6E=","X-Received":"by 2002:a05:6a00:850b:b0:82f:948f:d1db with SMTP id\n d2e1a72fcca58-82f949f19f4mr9062373b3a.44.1776749719398;\n Mon, 20 Apr 2026 22:35:19 -0700 (PDT)","From":"Ngo Luong Thanh Tra <ngotra27101996@gmail.com>","X-Google-Original-From":"Ngo Luong Thanh Tra <S4210155@student.rmit.edu.au>","To":"u-boot@lists.denx.de","Cc":"Ngo Luong Thanh Tra <S4210155@student.rmit.edu.au>,\n Alexander Sverdlin <alexander.sverdlin@siemens.com>,\n Casey Connolly <casey.connolly@linaro.org>,\n Patrice Chotard <patrice.chotard@foss.st.com>, Peng Fan <peng.fan@nxp.com>,\n Simon Glass <sjg@chromium.org>, Tom Rini <trini@konsulko.com>,\n Yao Zi <me@ziyao.cc>","Subject":"[PATCH] common: cli_hush: fix console_buffer overflow on boot retry","Date":"Tue, 21 Apr 2026 12:35:08 +0700","Message-ID":"<20260421053511.84312-1-S4210155@student.rmit.edu.au>","X-Mailer":"git-send-email 2.53.0","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","X-Mailman-Approved-At":"Tue, 21 Apr 2026 09:29:26 +0200","X-BeenThere":"u-boot@lists.denx.de","X-Mailman-Version":"2.1.39","Precedence":"list","List-Id":"U-Boot discussion <u-boot.lists.denx.de>","List-Unsubscribe":"<https://lists.denx.de/options/u-boot>,\n <mailto:u-boot-request@lists.denx.de?subject=unsubscribe>","List-Archive":"<https://lists.denx.de/pipermail/u-boot/>","List-Post":"<mailto:u-boot@lists.denx.de>","List-Help":"<mailto:u-boot-request@lists.denx.de?subject=help>","List-Subscribe":"<https://lists.denx.de/listinfo/u-boot>,\n <mailto:u-boot-request@lists.denx.de?subject=subscribe>","Errors-To":"u-boot-bounces@lists.denx.de","Sender":"\"U-Boot\" <u-boot-bounces@lists.denx.de>","X-Virus-Scanned":"clamav-milter 0.103.8 at phobos.denx.de","X-Virus-Status":"Clean"},"content":"Add const_strcpy() macro to linux/build_bug.h that enforces at\ncompile time that the destination is a writable char array (not char *\nor const char *), the source is a string literal, and the source fits\nin the destination including the NUL terminator.\n\nFix the console_buffer extern declaration in console.h to include the\narray size so sizeof(console_buffer) is valid at call sites.\n\nReplace unbounded strcpy() in cli_hush.c with const_strcpy().\n\nFixes: 657e19f8f2dd (\"cli_hush: support running bootcmd on boot retry\")\n\nChanges in v4:\n- Rebased on top of current master (as requested by Tom Rini)\n\nChanges in v3:\n- Reject const char * destinations in const_strcpy() (Simon Glass)\n\nSigned-off-by: Ngo Luong Thanh Tra <S4210155@student.rmit.edu.au>\n---\n\n common/cli_hush.c         |  3 ++-\n include/console.h         |  3 ++-\n include/linux/build_bug.h | 24 ++++++++++++++++++++++++\n 3 files changed, 28 insertions(+), 2 deletions(-)","diff":"diff --git a/common/cli_hush.c b/common/cli_hush.c\nindex fe8fe93bd54..d7a584fea3f 100644\n--- a/common/cli_hush.c\n+++ b/common/cli_hush.c\n@@ -84,6 +84,7 @@\n #include <cli_hush.h>\n #include <command.h>        /* find_cmd */\n #include <vsprintf.h>\n+#include <linux/build_bug.h>\n #endif\n #ifndef __U_BOOT__\n #include <ctype.h>     /* isalpha, isdigit */\n@@ -1027,7 +1028,7 @@ static void get_user_input(struct in_str *i)\n #  ifdef CONFIG_RESET_TO_RETRY\n \t  do_reset(NULL, 0, 0, NULL);\n #  elif IS_ENABLED(CONFIG_RETRY_BOOTCMD)\n-\tstrcpy(console_buffer, \"run bootcmd\\n\");\n+\tconst_strcpy(console_buffer, \"run bootcmd\\n\");\n # else\n #\terror \"This only works with CONFIG_RESET_TO_RETRY or CONFIG_BOOT_RETRY_COMMAND enabled\"\n #  endif\ndiff --git a/include/console.h b/include/console.h\nindex 8d0d7bb8a4c..97ccf5e5f6a 100644\n--- a/include/console.h\n+++ b/include/console.h\n@@ -10,8 +10,9 @@\n #include <stdbool.h>\n #include <stdio_dev.h>\n #include <linux/errno.h>\n+#include <config.h>\n \n-extern char console_buffer[];\n+extern char console_buffer[CONFIG_SYS_CBSIZE + 1];\n \n /* common/console.c */\n int console_init_f(void);\t/* Before relocation; uses the serial  stuff */\ndiff --git a/include/linux/build_bug.h b/include/linux/build_bug.h\nindex 20c2dc7f4bd..93f9e50a1c6 100644\n--- a/include/linux/build_bug.h\n+++ b/include/linux/build_bug.h\n@@ -76,4 +76,28 @@\n #define static_assert(expr, ...) __static_assert(expr, ##__VA_ARGS__, #expr)\n #define __static_assert(expr, msg, ...) _Static_assert(expr, msg)\n \n+/**\n+ * const_strcpy - Copy a string literal to a char array with compile-time checks\n+ * @d: destination char array (must be a char array, not a pointer)\n+ * @s: source string literal\n+ *\n+ * Enforces at compile time that:\n+ * (a) @d is a char array, not a pointer\n+ * (b) @s is a string literal (adjacent string concatenation trick)\n+ * (c) @s fits in @d including the NUL terminator\n+ *\n+ * Uses __builtin_strcpy() so the compiler can optimize the copy into\n+ * immediate stores rather than emitting a function call.\n+ *\n+ * Note: @s is used twice in the macro expansion but this is intentional\n+ * and safe: the (\"\" s \"\") trick enforces at compile time that @s is a\n+ * string literal, and string literals have no side effects.\n+ */\n+#define const_strcpy(d, s) ({\t\t\t\t\t\t\\\n+\tBUILD_BUG_ON(__builtin_types_compatible_p(typeof(d), char *));\t\\\n+\tBUILD_BUG_ON(__builtin_types_compatible_p(typeof(d), const char *));\t\\\n+\tBUILD_BUG_ON(sizeof(d) < sizeof(\"\" s \"\"));\t\t\t\\\n+\t__builtin_strcpy(d, s);\t\t\t\t\t\t\\\n+})\n+\n #endif\t/* _LINUX_BUILD_BUG_H */\n","prefixes":[]}