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
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to