Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 5 Apr 2013 09:14:31 +0000 (UTC)
From:      Andriy Gapon <avg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r249139 - head/sys/boot/common
Message-ID:  <201304050914.r359EVgO017442@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: avg
Date: Fri Apr  5 09:14:30 2013
New Revision: 249139
URL: http://svnweb.freebsd.org/changeset/base/249139

Log:
  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

Modified:
  head/sys/boot/common/util.c

Modified: head/sys/boot/common/util.c
==============================================================================
--- head/sys/boot/common/util.c	Fri Apr  5 09:06:59 2013	(r249138)
+++ head/sys/boot/common/util.c	Fri Apr  5 09:14:30 2013	(r249139)
@@ -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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201304050914.r359EVgO017442>