]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
safe-memfuncs: rely on explicit_bzero implementation from gnulib
authorDaiki Ueno <ueno@gnu.org>
Sat, 23 Jan 2021 13:36:57 +0000 (14:36 +0100)
committerDaiki Ueno <ueno@gnu.org>
Wed, 17 Feb 2021 17:09:46 +0000 (18:09 +0100)
Signed-off-by: Daiki Ueno <ueno@gnu.org>
.gitignore
bootstrap.conf
configure.ac
lib/safe-memfuncs.c
tests/Makefile.am
tests/memset.c [deleted file]

index 6981a7bf788664e1841f4a3e1780e90dcd3c5128..3bb1869176fcc50313ce197edbfa409dc64456bc 100644 (file)
@@ -468,9 +468,6 @@ tests/libpkcs11mock1.la
 tests/libpkcs11mock2.la
 tests/libutils.la
 tests/long-session-id
-tests/memset
-tests/memset0
-tests/memset1
 tests/mini
 tests/mini-alignment
 tests/mini-alpn
index f34508a3cb6954ac8ab53b194fd2fb73d68b1002..271b51f1436cd4878431c2d592ce6c403ca14464 100644 (file)
@@ -27,7 +27,7 @@ required_submodules="tests/suite/tls-fuzzer/python-ecdsa tests/suite/tls-fuzzer/
 
 # Those modules are common to lib/ and src/.
 common_modules="
-alloca attribute byteswap c-ctype c-strcase fopen-gnu func getline gettext-h gettimeofday hash hash-pjw-bare arpa_inet inet_ntop inet_pton intprops memmem-simple minmax netdb netinet_in read-file secure_getenv setsockopt snprintf stdint stpcpy strcase strdup-posix strndup strtok_r strverscmp sys_socket sys_stat sys_types threadlib time_r unistd valgrind-tests vasprintf verify vsnprintf
+alloca attribute byteswap c-ctype c-strcase explicit_bzero fopen-gnu func getline gettext-h gettimeofday hash hash-pjw-bare arpa_inet inet_ntop inet_pton intprops memmem-simple minmax netdb netinet_in read-file secure_getenv setsockopt snprintf stdint stpcpy strcase strdup-posix strndup strtok_r strverscmp sys_socket sys_stat sys_types threadlib time_r unistd valgrind-tests vasprintf verify vsnprintf
 "
 gnulib_modules="
 $common_modules extensions gendocs havelib ldd lib-msvc-compat lib-symbol-versions maintainer-makefile manywarnings pmccabe2html warnings
index 05985bd72d95f19eba1f7fa3d2299f018fc125bf..ee8ba5c0607f0a4877b1fb51fa5ad5fb1964b111 100644 (file)
@@ -355,7 +355,7 @@ AC_C_BIGENDIAN
 
 dnl No fork on MinGW, disable some self-tests until we fix them.
 dnl Check clock_gettime and pthread_mutex_lock in libc (avoid linking to other libs)
-AC_CHECK_FUNCS([fork setitimer getrusage getpwuid_r nanosleep daemon getpid localtime mmap explicit_bzero],,)
+AC_CHECK_FUNCS([fork setitimer getrusage getpwuid_r nanosleep daemon getpid localtime mmap],,)
 dnl Manually check some functions by including headers first. On macOS, you
 dnl normally only have the latest SDK available, containing all existing
 dnl functions, but having them restricted according to target version in
index b957b432cd87d28337df984f31582d862bdb404b..2be4db6da812595fee0ddb44fee1e5223ad447c5 100644 (file)
  **/
 void gnutls_memset(void *data, int c, size_t size)
 {
-       volatile unsigned volatile_zero;
-       volatile char *vdata = (volatile char*)data;
-#ifdef HAVE_EXPLICIT_BZERO
-       if (c == 0) {
-               explicit_bzero(data, size);
-               return;
-       }
-#endif
-       volatile_zero = 0;
-
-       /* This is based on a nice trick for safe memset,
-        * sent by David Jacobson in the openssl-dev mailing list.
-        */
-
-       if (size > 0) {
-               do {
-                       memset(data, c, size);
-               } while(vdata[volatile_zero] != c);
-       }
+       explicit_bzero(data, size);
+       memset(data, c, size);
 }
 
 /**
index 5ab6cb4ce5a98f8079344dc103dc13489fd26930..9a2a3e33ed358af675210fbd555464ff091cd673 100644 (file)
@@ -160,7 +160,7 @@ ctests += mini-record-2 simple gnutls_hmac_fast set_pkcs12_cred cert certuniquei
         mini-emsgsize-dtls chainverify-unsorted mini-overhead tls12-ffdhe \
         mini-dtls-heartbeat mini-x509-callbacks key-openssl priorities priorities-groups       \
         gnutls_x509_privkey_import gnutls_x509_crt_list_import time x509-server-verify \
-        sign-verify-ext4 tls-neg-ext4-key resume-lifetime memset0 memset1 \
+        sign-verify-ext4 tls-neg-ext4-key resume-lifetime \
         mini-dtls-srtp rsa-encrypt-decrypt mini-loss-time gnutls-strcodes \
         mini-record mini-dtls-record handshake-timeout mini-record-range \
         cert-status fips-mode-pthread rsa-psk global-init sec-params sign-verify-data \
@@ -270,14 +270,6 @@ fips_mode_pthread_LDADD = $(LDADD) -lpthread
 dtls_pthread_LDADD = $(LDADD) -lpthread
 rng_pthread_LDADD = $(LDADD) -lpthread
 
-memset0_CFLAGS = -DCHAR=0x0
-memset0_SOURCES = memset.c
-memset0_LDADD = $(LDADD)
-
-memset1_CFLAGS = -DCHAR=0xa
-memset1_SOURCES = memset.c
-memset1_LDADD = $(LDADD)
-
 tls12_rollback_detection_CFLAGS = -DTLS12
 tls12_rollback_detection_SOURCES = tls13/rnd-rollback-detection.c
 tls12_rollback_detection_LDADD = $(LDADD) ../gl/libgnu.la
diff --git a/tests/memset.c b/tests/memset.c
deleted file mode 100644 (file)
index f49cde4..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright (C) 2017 Red Hat, Inc.
- *
- * Author: Nikos Mavrogiannopoulos
- *
- * This file is part of GnuTLS.
- *
- * GnuTLS is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * GnuTLS is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program.  If not, see <https://www.gnu.org/licenses/>
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <string.h>
-#include <stdint.h>
-#include <gnutls/gnutls.h>
-
-#include "utils.h"
-
-#define BUF_SIZE 128
-
-void func1(void);
-void func2(void);
-
-static unsigned char *ptr;
-
-/* Checks whether gnutls_memset() call is being optimized
- * out.
- */
-
-void func1(void)
-{
-       unsigned char buf[BUF_SIZE];
-       ptr = buf;
-
-       gnutls_memset(buf, CHAR, sizeof(buf));
-}
-
-void func2(void)
-{
-       if (ptr[0] != CHAR || ptr[2] != CHAR || ptr[16] != CHAR)
-               fail("previous memset failed!\n");
-}
-
-void doit(void)
-{
-#if defined(__has_feature)
-#  if __has_feature(address_sanitizer)
-       exit(77);
-#  endif
-#endif
-
-#if __SANITIZE_ADDRESS__ == 1
-       exit(77);
-#endif
-
-       func1();
-       func2();
-       success("memset test succeeded\n");
-}