summaryrefslogtreecommitdiffstats
path: root/sys/boot/common
diff options
context:
space:
mode:
authoravg <avg@FreeBSD.org>2013-04-05 09:14:30 +0000
committeravg <avg@FreeBSD.org>2013-04-05 09:14:30 +0000
commit47b0933c6d1f9070043e74cfaaaab8a03ba2b47d (patch)
treec22e8b6fb4782d1014cb0529bfb7718dc4b4ae1e /sys/boot/common
parent5f76d7affd4776eaad39785ce42f58b6ac573e9b (diff)
downloadFreeBSD-src-47b0933c6d1f9070043e74cfaaaab8a03ba2b47d.zip
FreeBSD-src-47b0933c6d1f9070043e74cfaaaab8a03ba2b47d.tar.gz
strncmp for boot code: fix an off by one error
Before this change strncmp would access and _compare_ n+1 characters in the case where the first n characters match. MFC after: 5 days
Diffstat (limited to 'sys/boot/common')
-rw-r--r--sys/boot/common/util.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/sys/boot/common/util.c b/sys/boot/common/util.c
index 07f69a3..21834be 100644
--- a/sys/boot/common/util.c
+++ b/sys/boot/common/util.c
@@ -68,9 +68,9 @@ int
strncmp(const char *s1, const char *s2, size_t len)
{
- for (; *s1 == *s2 && *s1 != '\0' && len > 0; len--, s1++, s2++)
+ for (; len > 0 && *s1 == *s2 && *s1 != '\0'; len--, s1++, s2++)
;
- return ((unsigned char)*s1 - (unsigned char)*s2);
+ return (len == 0 ? 0 : (unsigned char)*s1 - (unsigned char)*s2);
}
void
OpenPOWER on IntegriCloud