]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
[v9_6] added isc_safe_memcmp()
authorEvan Hunt <each@isc.org>
Tue, 9 Jul 2013 21:18:56 +0000 (14:18 -0700)
committerEvan Hunt <each@isc.org>
Tue, 9 Jul 2013 21:18:56 +0000 (14:18 -0700)
3611.       [bug]           Improved resistance to a theoretical authentication
                            attack based on differential timing.  [RT #33939]
(cherry picked from commit 5b7abbef511cea0b568be0bc8d5b3120a0b9034d)
(cherry picked from commit a66c88dd260c0dd4707cbf00fd4dad9346562b09)
(cherry picked from commit 547ffae91c16d4b17c6dd72aba941ac1e36660a0)

16 files changed:
CHANGES
configure
configure.in
lib/dns/hmac_link.c
lib/isc/Makefile.in
lib/isc/hmacmd5.c
lib/isc/hmacsha.c
lib/isc/include/isc/Makefile.in
lib/isc/include/isc/safe.h [new file with mode: 0644]
lib/isc/safe.c [new file with mode: 0644]
lib/isc/tests/Makefile.in
lib/isc/tests/safe_test.c [new file with mode: 0644]
lib/isc/win32/libisc.def
lib/isc/win32/libisc.dsp
lib/isc/win32/libisc.mak
lib/isccc/cc.c

diff --git a/CHANGES b/CHANGES
index 56053f078de8513da74ce0f3952a1d2fa3c85bf5..30a8859829180e87b42ba148a9bd6da40bd8e872 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,6 @@
+3611.  [bug]           Improved resistance to a theoretical authentication
+                       attack based on differential timing.  [RT #33939]
+
 3608.  [port]          win32: added todos.pl script to ensure all text files
                        the win32 build depends on are converted to DOS
                        newline format. [RT #22067]
index ecc28bfd60aba7bdb6003568a7089c045e9fe245..6190e9420584c6246b6a93d7343ba6c25ac88866 100755 (executable)
--- a/configure
+++ b/configure
@@ -1316,6 +1316,7 @@ PERL
 ETAGS
 LN
 ARFLAGS
+CCNOOPT
 CCOPT
 STD_CWARNINGS
 STD_CDEFINES
@@ -11770,6 +11771,7 @@ fi
 
 
 
+
 # Warn if the user specified libbind, which is now deprecated
 # Check whether --enable-libbind was given.
 if test "${enable_libbind+set}" = set; then :
@@ -12692,6 +12694,13 @@ case "$host" in
          ;;
 esac
 
+#
+# CCNOOPT defaults to -O0 on gcc and disables optimization when is last
+#
+if test "X$CCNOOPT" = "X" -a "X$GCC" = "Xyes"; then
+       CCNOOPT="-O0"
+fi
+
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ANSI C header files" >&5
 $as_echo_n "checking for ANSI C header files... " >&6; }
 if ${ac_cv_header_stdc+:} false; then :
@@ -14856,11 +14865,13 @@ then
                *-freebsd*)
                        CC="$CC -pthread"
                        CCOPT="$CCOPT -pthread"
+                       CCNOOPT="$CCNOOPT -pthread"
                        STD_CDEFINES="$STD_CDEFINES -D_THREAD_SAFE"
                        ;;
                *-openbsd*)
                        CC="$CC -pthread"
                        CCOPT="$CCOPT -pthread"
+                       CCNOOPT="$CCNOOPT -pthread"
                        ;;
                *-solaris*)
                        LIBS="$LIBS -lthread"
@@ -14874,10 +14885,12 @@ then
                *-dec-osf*)
                        CC="$CC -pthread"
                        CCOPT="$CCOPT -pthread"
+                       CCNOOPT="$CCNOOPT -pthread"
                        ;;
                *-solaris*)
                        CC="$CC -mt"
                        CCOPT="$CCOPT -mt"
+                       CCNOOPT="$CCNOOPT -mt"
                        ;;
                *-ibm-aix*)
                        STD_CDEFINES="$STD_CDEFINES -D_THREAD_SAFE"
@@ -14885,10 +14898,12 @@ then
                *-sco-sysv*uw*|*-*-sysv*UnixWare*)
                        CC="$CC -Kthread"
                        CCOPT="$CCOPT -Kthread"
+                       CCNOOPT="$CCNOOPT -Kthread"
                        ;;
                *-*-sysv*OpenUNIX*)
                        CC="$CC -Kpthread"
                        CCOPT="$CCOPT -Kpthread"
+                       CCNOOPT="$CCNOOPT -Kpthread"
                        ;;
                esac
        fi
@@ -15376,6 +15391,7 @@ else
        *-dec-osf*)
                CC="$CC -std"
                CCOPT="$CCOPT -std"
+               CCNOOPT="$CCNOOPT -std"
                MKDEPCC="$CC"
                ;;
        *-hp-hpux*)
@@ -15394,6 +15410,7 @@ else
                        ;;
                esac
                CCOPT="$CCOPT -Ae -z"
+               CCNOOPT="$CCNOOPT -Ae -z"
                LDFLAGS="-Wl,+vnocompatwarnings $LDFLAGS"
                MKDEPPROG='cc -Ae -E -Wp,-M >/dev/null 2>>$TMP'
                ;;
index 43d0fef1120e1d82543f7b47cdb3108b6f1f7887..4274f7afe0234b8bbbbddac25161e9094354c409 100644 (file)
@@ -49,6 +49,7 @@ AC_SUBST(STD_CINCLUDES)
 AC_SUBST(STD_CDEFINES)
 AC_SUBST(STD_CWARNINGS)
 AC_SUBST(CCOPT)
+AC_SUBST(CCNOOPT)
 
 # Warn if the user specified libbind, which is now deprecated
 AC_ARG_ENABLE(libbind, [  --enable-libbind       deprecated])
@@ -295,6 +296,13 @@ case "$host" in
          ;;
 esac
 
+#
+# CCNOOPT defaults to -O0 on gcc and disables optimization when is last
+#
+if test "X$CCNOOPT" = "X" -a "X$GCC" = "Xyes"; then
+       CCNOOPT="-O0"
+fi
+
 AC_HEADER_STDC
 
 AC_CHECK_HEADERS(fcntl.h sys/time.h unistd.h sys/sockio.h sys/select.h sys/param.h sys/sysctl.h net/if6.h,,,
@@ -953,11 +961,13 @@ then
                *-freebsd*)
                        CC="$CC -pthread"
                        CCOPT="$CCOPT -pthread"
+                       CCNOOPT="$CCNOOPT -pthread"
                        STD_CDEFINES="$STD_CDEFINES -D_THREAD_SAFE"
                        ;;
                *-openbsd*)
                        CC="$CC -pthread"
                        CCOPT="$CCOPT -pthread"
+                       CCNOOPT="$CCNOOPT -pthread"
                        ;;
                *-solaris*)
                        LIBS="$LIBS -lthread"
@@ -971,10 +981,12 @@ then
                *-dec-osf*)
                        CC="$CC -pthread"
                        CCOPT="$CCOPT -pthread"
+                       CCNOOPT="$CCNOOPT -pthread"
                        ;;
                *-solaris*)
                        CC="$CC -mt"
                        CCOPT="$CCOPT -mt"
+                       CCNOOPT="$CCNOOPT -mt"
                        ;;
                *-ibm-aix*)
                        STD_CDEFINES="$STD_CDEFINES -D_THREAD_SAFE"
@@ -982,10 +994,12 @@ then
                *-sco-sysv*uw*|*-*-sysv*UnixWare*)
                        CC="$CC -Kthread"
                        CCOPT="$CCOPT -Kthread"
+                       CCNOOPT="$CCNOOPT -Kthread"
                        ;;
                *-*-sysv*OpenUNIX*)
                        CC="$CC -Kpthread"
                        CCOPT="$CCOPT -Kpthread"
+                       CCNOOPT="$CCNOOPT -Kpthread"
                        ;;
                esac
        fi
@@ -1195,6 +1209,7 @@ else
        *-dec-osf*)
                CC="$CC -std"
                CCOPT="$CCOPT -std"
+               CCNOOPT="$CCNOOPT -std"
                MKDEPCC="$CC"
                ;;
        *-hp-hpux*)
@@ -1213,6 +1228,7 @@ else
                        ;;
                esac
                CCOPT="$CCOPT -Ae -z"
+               CCNOOPT="$CCNOOPT -Ae -z"
                LDFLAGS="-Wl,+vnocompatwarnings $LDFLAGS"
                MKDEPPROG='cc -Ae -E -Wp,-M >/dev/null 2>>$TMP'
                ;;
index 908154464c1d076fb7ae552bc76cf787c841a499..c8b32079b2e74a2604cf39d1e242fd2aa43d07f3 100644 (file)
@@ -42,6 +42,7 @@
 #include <isc/md5.h>
 #include <isc/sha1.h>
 #include <isc/mem.h>
+#include <isc/safe.h>
 #include <isc/string.h>
 #include <isc/util.h>
 
@@ -142,7 +143,7 @@ hmacmd5_compare(const dst_key_t *key1, const dst_key_t *key2) {
        else if (hkey1 == NULL || hkey2 == NULL)
                return (ISC_FALSE);
 
-       if (memcmp(hkey1->key, hkey2->key, HMAC_LEN) == 0)
+       if (isc_safe_memcmp(hkey1->key, hkey2->key, HMAC_LEN))
                return (ISC_TRUE);
        else
                return (ISC_FALSE);
@@ -411,7 +412,7 @@ hmacsha1_compare(const dst_key_t *key1, const dst_key_t *key2) {
        else if (hkey1 == NULL || hkey2 == NULL)
                return (ISC_FALSE);
 
-       if (memcmp(hkey1->key, hkey2->key, ISC_SHA1_DIGESTLENGTH) == 0)
+       if (isc_safe_memcmp(hkey1->key, hkey2->key, ISC_SHA1_DIGESTLENGTH))
                return (ISC_TRUE);
        else
                return (ISC_FALSE);
@@ -681,7 +682,7 @@ hmacsha224_compare(const dst_key_t *key1, const dst_key_t *key2) {
        else if (hkey1 == NULL || hkey2 == NULL)
                return (ISC_FALSE);
 
-       if (memcmp(hkey1->key, hkey2->key, ISC_SHA224_DIGESTLENGTH) == 0)
+       if (isc_safe_memcmp(hkey1->key, hkey2->key, ISC_SHA224_DIGESTLENGTH))
                return (ISC_TRUE);
        else
                return (ISC_FALSE);
@@ -951,7 +952,7 @@ hmacsha256_compare(const dst_key_t *key1, const dst_key_t *key2) {
        else if (hkey1 == NULL || hkey2 == NULL)
                return (ISC_FALSE);
 
-       if (memcmp(hkey1->key, hkey2->key, ISC_SHA256_DIGESTLENGTH) == 0)
+       if (isc_safe_memcmp(hkey1->key, hkey2->key, ISC_SHA256_DIGESTLENGTH))
                return (ISC_TRUE);
        else
                return (ISC_FALSE);
@@ -1221,7 +1222,7 @@ hmacsha384_compare(const dst_key_t *key1, const dst_key_t *key2) {
        else if (hkey1 == NULL || hkey2 == NULL)
                return (ISC_FALSE);
 
-       if (memcmp(hkey1->key, hkey2->key, ISC_SHA384_DIGESTLENGTH) == 0)
+       if (isc_safe_memcmp(hkey1->key, hkey2->key, ISC_SHA384_DIGESTLENGTH))
                return (ISC_TRUE);
        else
                return (ISC_FALSE);
@@ -1491,7 +1492,7 @@ hmacsha512_compare(const dst_key_t *key1, const dst_key_t *key2) {
        else if (hkey1 == NULL || hkey2 == NULL)
                return (ISC_FALSE);
 
-       if (memcmp(hkey1->key, hkey2->key, ISC_SHA512_DIGESTLENGTH) == 0)
+       if (isc_safe_memcmp(hkey1->key, hkey2->key, ISC_SHA512_DIGESTLENGTH))
                return (ISC_TRUE);
        else
                return (ISC_FALSE);
index 14b4e826a287355003291ba9b4db7ad7c6d36694..8ea6400e05bd3ff17b7e31bac89238c5b26bebce 100644 (file)
@@ -61,7 +61,7 @@ OBJS =                @ISC_EXTRA_OBJS@ \
                netaddr.@O@ netscope.@O@ ondestroy.@O@ \
                parseint.@O@ portset.@O@ quota.@O@ radix.@O@ random.@O@ \
                ratelimiter.@O@ refcount.@O@ region.@O@ result.@O@ rwlock.@O@ \
-               serial.@O@ sha1.@O@ sha2.@O@ sockaddr.@O@ stats.@O@ \
+               safe.@O@ serial.@O@ sha1.@O@ sha2.@O@ sockaddr.@O@ stats.@O@ \
                string.@O@ strtoul.@O@ symtab.@O@ task.@O@ taskpool.@O@ \
                timer.@O@ version.@O@ ${UNIXOBJS} ${NLSOBJS} ${THREADOBJS}
 
@@ -76,8 +76,9 @@ SRCS =                @ISC_EXTRA_SRCS@ \
                netaddr.c netscope.c ondestroy.c \
                parseint.c portset.c quota.c radix.c random.c \
                ratelimiter.c refcount.c region.c result.c rwlock.c \
-               serial.c sha1.c sha2.c sockaddr.c stats.c string.c strtoul.c \
-               symtab.c task.c taskpool.c timer.c version.c
+               safe.c serial.c sha1.c sha2.c sockaddr.c stats.c \
+               string.c strtoul.c symtab.c \
+               task.c taskpool.c timer.c version.c
 
 LIBS =         @LIBS@
 
@@ -91,6 +92,10 @@ TESTDIRS =   @UNITTESTS@
 
 @BIND9_MAKE_RULES@
 
+safe.@O@: safe.c
+       ${LIBTOOL_MODE_COMPILE} ${CC} ${ALL_CFLAGS} @CCNOOPT@ \
+               -c ${srcdir}/safe.c
+
 version.@O@: version.c
        ${LIBTOOL_MODE_COMPILE} ${CC} ${ALL_CFLAGS} \
                -DVERSION=\"${VERSION}\" \
index 5d761e4d4581f5dc5cbe1127dc2336c96db3bac8..cb3c90d0cd4e7668994f788ed0018e8ebd47020c 100644 (file)
@@ -27,6 +27,7 @@
 #include <isc/assertions.h>
 #include <isc/hmacmd5.h>
 #include <isc/md5.h>
+#include <isc/safe.h>
 #include <isc/string.h>
 #include <isc/types.h>
 #include <isc/util.h>
@@ -114,5 +115,5 @@ isc_hmacmd5_verify2(isc_hmacmd5_t *ctx, unsigned char *digest, size_t len) {
 
        REQUIRE(len <= ISC_MD5_DIGESTLENGTH);
        isc_hmacmd5_sign(ctx, newdigest);
-       return (ISC_TF(memcmp(digest, newdigest, len) == 0));
+       return (isc_safe_memcmp(digest, newdigest, len));
 }
index 0bd78d7b2301e72665c077a6c5a62e9758d93286..2060c9db1054d95abc3b3b777495addd8366f42d 100644 (file)
@@ -26,6 +26,7 @@
 
 #include <isc/assertions.h>
 #include <isc/hmacsha.h>
+#include <isc/safe.h>
 #include <isc/sha1.h>
 #include <isc/sha2.h>
 #include <isc/string.h>
@@ -113,7 +114,7 @@ isc_hmacsha1_verify(isc_hmacsha1_t *ctx, unsigned char *digest, size_t len) {
 
        REQUIRE(len <= ISC_SHA1_DIGESTLENGTH);
        isc_hmacsha1_sign(ctx, newdigest, ISC_SHA1_DIGESTLENGTH);
-       return (ISC_TF(memcmp(digest, newdigest, len) == 0));
+       return (isc_safe_memcmp(digest, newdigest, len));
 }
 
 /*
@@ -192,7 +193,7 @@ isc_hmacsha224_verify(isc_hmacsha224_t *ctx, unsigned char *digest, size_t len)
 
        REQUIRE(len <= ISC_SHA224_DIGESTLENGTH);
        isc_hmacsha224_sign(ctx, newdigest, ISC_SHA224_DIGESTLENGTH);
-       return (ISC_TF(memcmp(digest, newdigest, len) == 0));
+       return (isc_safe_memcmp(digest, newdigest, len));
 }
 
 /*
@@ -271,7 +272,7 @@ isc_hmacsha256_verify(isc_hmacsha256_t *ctx, unsigned char *digest, size_t len)
 
        REQUIRE(len <= ISC_SHA256_DIGESTLENGTH);
        isc_hmacsha256_sign(ctx, newdigest, ISC_SHA256_DIGESTLENGTH);
-       return (ISC_TF(memcmp(digest, newdigest, len) == 0));
+       return (isc_safe_memcmp(digest, newdigest, len));
 }
 
 /*
@@ -350,7 +351,7 @@ isc_hmacsha384_verify(isc_hmacsha384_t *ctx, unsigned char *digest, size_t len)
 
        REQUIRE(len <= ISC_SHA384_DIGESTLENGTH);
        isc_hmacsha384_sign(ctx, newdigest, ISC_SHA384_DIGESTLENGTH);
-       return (ISC_TF(memcmp(digest, newdigest, len) == 0));
+       return (isc_safe_memcmp(digest, newdigest, len));
 }
 
 /*
@@ -429,5 +430,5 @@ isc_hmacsha512_verify(isc_hmacsha512_t *ctx, unsigned char *digest, size_t len)
 
        REQUIRE(len <= ISC_SHA512_DIGESTLENGTH);
        isc_hmacsha512_sign(ctx, newdigest, ISC_SHA512_DIGESTLENGTH);
-       return (ISC_TF(memcmp(digest, newdigest, len) == 0));
+       return (isc_safe_memcmp(digest, newdigest, len));
 }
index d48ac85a7cd6d2a04b0671ee2f7b8a6972b72f14..791b03b47e23e13389a53fea9ff30c2ffbebce65 100644 (file)
@@ -37,9 +37,9 @@ HEADERS =     app.h assertions.h base64.h bitstring.h boolean.h buffer.h \
                mutexblock.h netaddr.h ondestroy.h os.h parseint.h \
                print.h quota.h radix.h random.h ratelimiter.h \
                refcount.h region.h resource.h \
-               result.h resultclass.h rwlock.h serial.h sha1.h sha2.h \
-               sockaddr.h socket.h stdio.h stdlib.h string.h \
-               symtab.h \
+               result.h resultclass.h rwlock.h \
+               safe.h serial.h sha1.h sha2.h \
+               sockaddr.h socket.h stdio.h stdlib.h string.h symtab.h \
                task.h taskpool.h timer.h types.h util.h version.h \
                xml.h
 
diff --git a/lib/isc/include/isc/safe.h b/lib/isc/include/isc/safe.h
new file mode 100644 (file)
index 0000000..89d56de
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2013  Internet Systems Consortium, Inc. ("ISC")
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+ * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+ * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/* $Id$ */
+
+#ifndef ISC_SAFE_H
+#define ISC_SAFE_H 1
+
+/*! \file isc/safe.h */
+
+#include <isc/types.h>
+
+ISC_LANG_BEGINDECLS
+
+isc_boolean_t
+isc_safe_memcmp(const void *s1, const void *s2, size_t n);
+/*%<
+ * Clone of libc memcmp() safe to differential timing attacks.
+ */
+
+ISC_LANG_ENDDECLS
+
+#endif /* ISC_SAFE_H */
diff --git a/lib/isc/safe.c b/lib/isc/safe.c
new file mode 100644 (file)
index 0000000..3f005d3
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2013  Internet Systems Consortium, Inc. ("ISC")
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+ * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+ * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/* $Id$ */
+
+/*! \file */
+
+#include <config.h>
+
+#include <isc/safe.h>
+#include <isc/util.h>
+
+#ifdef _MSC_VER
+#pragma optimize("", off)
+#endif
+
+isc_boolean_t
+isc_safe_memcmp(const void *s1, const void *s2, size_t n) {
+       isc_uint8_t acc = 0;
+
+       if (n != 0) {
+               const isc_uint8_t *p1 = s1, *p2 = s2;
+
+               do {
+                       acc |= *p1++ ^ *p2++;
+               } while (--n != 0);
+       }
+       return (ISC_TF(acc == 0));
+}
index 31977c695130ebf3ddd82e27e0b7f6d592d96059..9c5e7b7afc14de52356f89c43c60db2b92778498 100644 (file)
@@ -36,11 +36,11 @@ LIBS =              @LIBS@ @ATFLIBS@
 
 OBJS =         isctest.@O@
 
-SRCS =         isctest.c hash_test.c sockaddr_test.c \
+SRCS =         isctest.c hash_test.c safe_test.c sockaddr_test.c \
                symtab_test.c parse_test.c
 
 SUBDIRS =
-TARGETS =      hash_test@EXEEXT@ sockaddr_test@EXEEXT@ \
+TARGETS =      hash_test@EXEEXT@ safe_test@EXEEXT@ sockaddr_test@EXEEXT@ \
                symtab_test@EXEEXT@ parse_test@EXEEXT@
 
 @BIND9_MAKE_RULES@
@@ -61,6 +61,10 @@ sockaddr_test@EXEEXT@: sockaddr_test.@O@ isctest.@O@ ${ISCDEPLIBS}
        ${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
                        sockaddr_test.@O@ isctest.@O@ ${ISCLIBS} ${LIBS}
 
+safe_test@EXEEXT@: safe_test.@O@ ${ISCDEPLIBS}
+       ${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
+                       safe_test.@O@ ${ISCLIBS} ${LIBS}
+
 unit::
        sh ${top_srcdir}/unit/unittest.sh
 
diff --git a/lib/isc/tests/safe_test.c b/lib/isc/tests/safe_test.c
new file mode 100644 (file)
index 0000000..7b7ac39
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2013  Internet Systems Consortium, Inc. ("ISC")
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+ * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+ * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/* $Id$ */
+
+/* ! \file */
+
+#include <config.h>
+
+#include <atf-c.h>
+
+#include <stdio.h>
+#include <string.h>
+
+#include <isc/safe.h>
+#include <isc/util.h>
+
+ATF_TC(isc_safe_memcmp);
+ATF_TC_HEAD(isc_safe_memcmp, tc) {
+       atf_tc_set_md_var(tc, "descr", "safe memcmp()");
+}
+ATF_TC_BODY(isc_safe_memcmp, tc) {
+       UNUSED(tc);
+
+       ATF_CHECK(isc_safe_memcmp("test", "test", 4));
+       ATF_CHECK(!isc_safe_memcmp("test", "tesc", 4));
+       ATF_CHECK(isc_safe_memcmp("\x00\x00\x00\x00", "\x00\x00\x00\x00", 4));
+       ATF_CHECK(!isc_safe_memcmp("\x00\x00\x00\x00", "\x00\x00\x00\x01", 4));
+       ATF_CHECK(!isc_safe_memcmp("\x00\x00\x00\x02", "\x00\x00\x00\x00", 4));
+}
+
+/*
+ * Main
+ */
+ATF_TP_ADD_TCS(tp) {
+       ATF_TP_ADD_TC(tp, isc_safe_memcmp);
+       return (atf_no_error());
+}
+
index 9a86c6188e835dc690454b96c3da9bd4f9de5912..1a7eafa6448aee0015525ff296b9e72d49a07c85 100644 (file)
@@ -374,6 +374,7 @@ isc_rwlock_lock
 isc_rwlock_trylock
 isc_rwlock_tryupgrade
 isc_rwlock_unlock
+isc_safe_memcmp
 isc_serial_eq
 isc_serial_ge
 isc_serial_gt
index 820844364f64902e01a69aa1de5f808074df2e68..600eca83afcb28df50ed1a1886507f2968e1a666 100644 (file)
@@ -729,6 +729,10 @@ SOURCE=..\rwlock.c
 # End Source File\r
 # Begin Source File\r
 \r
+SOURCE=..\safe.c\r
+# End Source File\r
+# Begin Source File\r
+\r
 SOURCE=..\serial.c\r
 # End Source File\r
 # Begin Source File\r
index 47d7b970726306d146002eeaf24975ec206f1983..efc32cfbe09c8e404dccd7959bf8de4106e88c66 100644 (file)
@@ -169,6 +169,7 @@ CLEAN :
        -@erase "$(INTDIR)\resource.obj"
        -@erase "$(INTDIR)\result.obj"
        -@erase "$(INTDIR)\rwlock.obj"
+       -@erase "$(INTDIR)\safe.obj"
        -@erase "$(INTDIR)\serial.obj"
        -@erase "$(INTDIR)\sha1.obj"
        -@erase "$(INTDIR)\sha2.obj"
@@ -270,6 +271,7 @@ LINK32_OBJS= \
        "$(INTDIR)\refcount.obj" \
        "$(INTDIR)\result.obj" \
        "$(INTDIR)\rwlock.obj" \
+       "$(INTDIR)\safe.obj" \
        "$(INTDIR)\serial.obj" \
        "$(INTDIR)\sha1.obj" \
        "$(INTDIR)\sha2.obj" \
@@ -414,6 +416,8 @@ CLEAN :
        -@erase "$(INTDIR)\result.sbr"
        -@erase "$(INTDIR)\rwlock.obj"
        -@erase "$(INTDIR)\rwlock.sbr"
+       -@erase "$(INTDIR)\safe.obj"
+       -@erase "$(INTDIR)\safe.sbr"
        -@erase "$(INTDIR)\serial.obj"
        -@erase "$(INTDIR)\serial.sbr"
        -@erase "$(INTDIR)\sha1.obj"
@@ -533,6 +537,7 @@ BSC32_SBRS= \
        "$(INTDIR)\refcount.sbr" \
        "$(INTDIR)\result.sbr" \
        "$(INTDIR)\rwlock.sbr" \
+       "$(INTDIR)\safe.sbr" \
        "$(INTDIR)\serial.sbr" \
        "$(INTDIR)\sha1.sbr" \
        "$(INTDIR)\sha2.sbr" \
@@ -619,6 +624,7 @@ LINK32_OBJS= \
        "$(INTDIR)\refcount.obj" \
        "$(INTDIR)\result.obj" \
        "$(INTDIR)\rwlock.obj" \
+       "$(INTDIR)\safe.obj" \
        "$(INTDIR)\serial.obj" \
        "$(INTDIR)\sha1.obj" \
        "$(INTDIR)\sha2.obj" \
@@ -1801,6 +1807,24 @@ SOURCE=..\rwlock.c
        $(CPP) $(CPP_PROJ) $(SOURCE)
 
 
+!ENDIF 
+
+SOURCE=..\safe.c
+
+!IF  "$(CFG)" == "libisc - Win32 Release"
+
+
+"$(INTDIR)\safe.obj" : $(SOURCE) "$(INTDIR)"
+       $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
+!ELSEIF  "$(CFG)" == "libisc - Win32 Debug"
+
+
+"$(INTDIR)\safe.obj"   "$(INTDIR)\safe.sbr" : $(SOURCE) "$(INTDIR)"
+       $(CPP) $(CPP_PROJ) $(SOURCE)
+
+
 !ENDIF 
 
 SOURCE=..\serial.c
index 07f8157b0aa677d454fa5280864243db93e68964..65e889e34ce3fbc2f057ffd6f92678fcd122eb4a 100644 (file)
@@ -42,6 +42,7 @@
 #include <isc/assertions.h>
 #include <isc/hmacmd5.h>
 #include <isc/print.h>
+#include <isc/safe.h>
 #include <isc/stdlib.h>
 
 #include <isccc/alist.h>
@@ -311,7 +312,8 @@ verify(isccc_sexpr_t *alist, unsigned char *data, unsigned int length,
        /*
         * Verify.
         */
-       if (strcmp((char *)digestb64, isccc_sexpr_tostring(hmd5)) != 0)
+       if (!isc_safe_memcmp((unsigned char *) isccc_sexpr_tostring(hmd5),
+                            digestb64, HMD5_LENGTH))
                return (ISCCC_R_BADAUTH);
 
        return (ISC_R_SUCCESS);