mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH v1] string: add sanity check to the strcmp() and strncmp()
@ 2020-08-13 11:39 Oleksij Rempel
  2020-08-17  6:26 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Oleksij Rempel @ 2020-08-13 11:39 UTC (permalink / raw)
  To: barebox; +Cc: Oleksij Rempel

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH v1] string: add sanity check to the strcmp() and strncmp()
  2020-08-13 11:39 [PATCH v1] string: add sanity check to the strcmp() and strncmp() Oleksij Rempel
@ 2020-08-17  6:26 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2020-08-17  6:26 UTC (permalink / raw)
  To: Oleksij Rempel; +Cc: barebox

On Thu, Aug 13, 2020 at 01:39:38PM +0200, Oleksij Rempel wrote:
> 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(+)

Applied, thanks

Sascha


-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-08-17  6:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-13 11:39 [PATCH v1] string: add sanity check to the strcmp() and strncmp() Oleksij Rempel
2020-08-17  6:26 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox