[PATCH v1] string: add sanity check to the strcmp() and strncmp()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxx>
---
 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@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox



[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux