From 03d4ae76841bc9be62b5cc713fd84ccec1de9f12 Mon Sep 17 00:00:00 2001 From: Hannah Williams Date: Tue, 1 Dec 2015 09:30:27 -0800 Subject: lib: Fix strncmp strncmp continues to compare the characters in the input strings past any null termination it may encounter. Null termination check is added. Reviewed-on: https://chromium-review.googlesource.com/314815 Reviewed-by: Aaron Durbin Commit-Queue: Hannah Williams Tested-by: Hannah Williams (cherry picked from commit ca7022752115eddbcb776f0c0d778249555ddf32) Reviewed-on: https://chromium-review.googlesource.com/315130 Change-Id: Ifc378966dcf6023efe3d32b026cc89d69b0bb990 Signed-off-by: Hannah Williams Reviewed-on: https://review.coreboot.org/12721 Tested-by: build bot (Jenkins) Reviewed-by: Paul Menzel Reviewed-by: Aaron Durbin --- src/include/string.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/include/string.h') diff --git a/src/include/string.h b/src/include/string.h index b862194979..125c676128 100644 --- a/src/include/string.h +++ b/src/include/string.h @@ -112,7 +112,7 @@ static inline int strncmp(const char *s1, const char *s2, int maxlen) int i; for (i = 0; i < maxlen; i++) { - if (s1[i] != s2[i]) + if ((s1[i] != s2[i]) || (s1[i] == '\0')) return s1[i] - s2[i]; } -- cgit v1.2.3