From: Kay Potthoff <kaypotthoff@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] mtdparts: fixed buffer overflow bug
Date: Tue, 17 Jul 2018 08:19:39 +0200 [thread overview]
Message-ID: <20180717061939.6034-1-Kay.Potthoff@microsys.de> (raw)
In the case that there was no name defined for a partition the
code assumes that name_len is 22 and therefore allocates exactly
that space for a dummy name. But the function sprintf() first
resolves "0x%08llx at 0x%08llx" to a string that is longer than 22
bytes. This leads to a buffer overflow. The replacement function
snprintf() limits the copied bytes to name_len and therefore
avoids the buffer overflow.
Signed-off-by: Kay Potthoff <Kay.Potthoff@microsys.de>
---
cmd/mtdparts.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/cmd/mtdparts.c b/cmd/mtdparts.c
index 9bc977450cf8..d0cda1bea400 100644
--- a/cmd/mtdparts.c
+++ b/cmd/mtdparts.c
@@ -691,7 +691,7 @@ static int part_parse(const char *const partdef, const char **ret, struct part_i
part->auto_name = 0;
} else {
/* auto generated name in form of size at offset */
- sprintf(part->name, "0x%08llx at 0x%08llx", size, offset);
+ snprintf(part->name, name_len, "0x%08llx at 0x%08llx", size, offset);
part->auto_name = 1;
}
--
2.17.0
next reply other threads:[~2018-07-17 6:19 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-17 6:19 Kay Potthoff [this message]
2018-07-26 19:54 ` [U-Boot] mtdparts: fixed buffer overflow bug Tom Rini
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=20180717061939.6034-1-Kay.Potthoff@microsys.de \
--to=kaypotthoff@gmail.com \
--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