From: Oleksij Rempel <o.rempel@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Oleksij Rempel <o.rempel@pengutronix.de>
Subject: [PATCH v1] string: add sanity check to the strcmp() and strncmp()
Date: Thu, 13 Aug 2020 13:39:38 +0200 [thread overview]
Message-ID: <20200813113938.24127-1-o.rempel@pengutronix.de> (raw)
A relatively big portion of barebox init sequence is running without
configured exception vector. As result we may not detect some NULL
pointer dereferences (as on iMX6) or just silently freeze (as on stm32).
So, add sanity check to detect this kind of issues as early as possible.
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
lib/string.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/lib/string.c b/lib/string.c
index 717b59aa50..7548fd3581 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -208,6 +208,8 @@ int strcmp(const char * cs,const char * ct)
{
register signed char __res;
+ BUG_ON(!cs || !ct);
+
while (1) {
if ((__res = *cs - *ct++) != 0 || !*cs++)
break;
@@ -229,6 +231,8 @@ int strncmp(const char * cs, const char * ct, size_t count)
{
register signed char __res = 0;
+ BUG_ON(!cs || !ct);
+
while (count) {
if ((__res = *cs - *ct++) != 0 || !*cs++)
break;
--
2.28.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next reply other threads:[~2020-08-13 11:39 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-13 11:39 Oleksij Rempel [this message]
2020-08-17 6:26 ` Sascha Hauer
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=20200813113938.24127-1-o.rempel@pengutronix.de \
--to=o.rempel@pengutronix.de \
--cc=barebox@lists.infradead.org \
/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