diff options
author | Oleksij Rempel <o.rempel@pengutronix.de> | 2020-08-13 13:39:38 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2020-08-17 12:31:26 +0200 |
commit | a662c814ce1f262e846e2ec5e60e6631b4bb3c2e (patch) | |
tree | fe449610106987fa872b29fe3a87bd09b59a707a /lib | |
parent | c4065752b625f72f391cf17b0a41adbbb82e8052 (diff) | |
download | barebox-a662c814ce1f262e846e2ec5e60e6631b4bb3c2e.tar.gz barebox-a662c814ce1f262e846e2ec5e60e6631b4bb3c2e.tar.xz |
string: add sanity check to the strcmp() and strncmp()
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>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/string.c | 4 |
1 files changed, 4 insertions, 0 deletions
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; |