[U-Boot] [PATCH] cmd_mtdparts.c: prevent printbuffer overflows
Wolfgang Denk
wd at denx.de
Tue Feb 23 15:25:46 CET 2010
Dear Anatolij Gustschin,
In message <1266924140-14457-1-git-send-email-agust at denx.de> you wrote:
> The length of configured MTDPARTS_DEFAULT string
> could be greather than console printbuffer size.
> Check the lenght of the string before printing
> to prevent U-Boot crashes.
>
> Signed-off-by: Anatolij Gustschin <agust at denx.de>
> ---
> common/cmd_mtdparts.c | 8 ++++++++
> 1 files changed, 8 insertions(+), 0 deletions(-)
>
> diff --git a/common/cmd_mtdparts.c b/common/cmd_mtdparts.c
> index 230e96e..d4cb194 100644
> --- a/common/cmd_mtdparts.c
> +++ b/common/cmd_mtdparts.c
> @@ -1254,6 +1254,14 @@ static void list_partitions(void)
> printf("\ndefaults:\n");
> printf("mtdids : %s\n",
> mtdids_default ? mtdids_default : "none");
> +
> + /* Check to prevent printbuffer overflows */
> + if (mtdparts_default && strlen(mtdparts_default) > CONFIG_SYS_PBSIZE) {
> + puts("Warning: mtdparts too long,"
> + " please increase CONFIG_SYS_PBSIZE\n");
> + return;
> + }
> +
Instead of adding essentially dead code that does not really help the
end user, it would be better to avoid the potential problems. As log
as the console code has not been improved, it may make sense to avoid
printf() when you don't really need it.
I recommend to change this
> printf("mtdparts: %s\n",
> mtdparts_default ? mtdparts_default : "none");
into something like
puts("mtdparts: ");
puts(mtdparts_default ? mtdparts_default : "none");
Best regards,
Wolfgang Denk
--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
"Unix is simple, but it takes a genius to understand the simplicity."
- Dennis Ritchie
More information about the U-Boot
mailing list