aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrent Cook <bcook@openbsd.org>2017-03-16 19:23:36 -0500
committerBrent Cook <bcook@openbsd.org>2017-03-16 19:23:36 -0500
commitd5b247cc4fe0f3dd6cc4f7084af7f290ba41e669 (patch)
treeecff511a1a175c88222a9c83872920d512671717
parent8f69fe98dba08e22dd1341cbaad91745c8bf7ad7 (diff)
parentc61c9821e8417243a5a0cf691415f5e5626f2b3b (diff)
downloadportable-d5b247cc4fe0f3dd6cc4f7084af7f290ba41e669.tar.gz
portable-d5b247cc4fe0f3dd6cc4f7084af7f290ba41e669.tar.bz2
portable-d5b247cc4fe0f3dd6cc4f7084af7f290ba41e669.zip
Land #297, Add recallocarray
-rw-r--r--.gitignore1
-rw-r--r--crypto/CMakeLists.txt9
-rw-r--r--crypto/Makefile.am8
-rw-r--r--crypto/compat/getpagesize.c18
-rw-r--r--include/compat/stdlib.h4
-rw-r--r--include/compat/unistd.h4
-rw-r--r--m4/check-libc.m410
-rwxr-xr-xupdate.sh1
8 files changed, 53 insertions, 2 deletions
diff --git a/.gitignore b/.gitignore
index 5543d7a..052804e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -142,6 +142,7 @@ include/openssl/*.h
142!/crypto/compat/arc4random.h 142!/crypto/compat/arc4random.h
143!/crypto/compat/b_win.c 143!/crypto/compat/b_win.c
144!/crypto/compat/explicit_bzero_win.c 144!/crypto/compat/explicit_bzero_win.c
145!/crypto/compat/getpagesize.c
145!/crypto/compat/posix_win.c 146!/crypto/compat/posix_win.c
146!/crypto/compat/bsd_asprintf.c 147!/crypto/compat/bsd_asprintf.c
147!/crypto/compat/inet_pton.c 148!/crypto/compat/inet_pton.c
diff --git a/crypto/CMakeLists.txt b/crypto/CMakeLists.txt
index 47f0077..d7b65e2 100644
--- a/crypto/CMakeLists.txt
+++ b/crypto/CMakeLists.txt
@@ -681,6 +681,10 @@ if(NOT HAVE_ASPRINTF)
681 set(EXTRA_EXPORT ${EXTRA_EXPORT} vasprintf) 681 set(EXTRA_EXPORT ${EXTRA_EXPORT} vasprintf)
682endif() 682endif()
683 683
684if(NOT HAVE_GETPAGESIZE)
685 set(CRYPTO_SRC ${CRYPTO_SRC} compat/getpagesize.c)
686endif()
687
684if(NOT HAVE_INET_PTON) 688if(NOT HAVE_INET_PTON)
685 set(CRYPTO_SRC ${CRYPTO_SRC} compat/inet_pton.c) 689 set(CRYPTO_SRC ${CRYPTO_SRC} compat/inet_pton.c)
686 set(EXTRA_EXPORT ${EXTRA_EXPORT} inet_pton) 690 set(EXTRA_EXPORT ${EXTRA_EXPORT} inet_pton)
@@ -691,6 +695,11 @@ if(NOT HAVE_REALLOCARRAY)
691 set(EXTRA_EXPORT ${EXTRA_EXPORT} reallocarray) 695 set(EXTRA_EXPORT ${EXTRA_EXPORT} reallocarray)
692endif() 696endif()
693 697
698if(NOT HAVE_RECALLOCARRAY)
699 set(CRYPTO_SRC ${CRYPTO_SRC} compat/recallocarray.c)
700 set(EXTRA_EXPORT ${EXTRA_EXPORT} recallocarray)
701endif()
702
694if(NOT HAVE_STRCASECMP) 703if(NOT HAVE_STRCASECMP)
695 set(CRYPTO_SRC ${CRYPTO_SRC} compat/strcasecmp.c) 704 set(CRYPTO_SRC ${CRYPTO_SRC} compat/strcasecmp.c)
696 set(EXTRA_EXPORT ${EXTRA_EXPORT} strcasecmp) 705 set(EXTRA_EXPORT ${EXTRA_EXPORT} strcasecmp)
diff --git a/crypto/Makefile.am b/crypto/Makefile.am
index 23aaeac..dc94a8c 100644
--- a/crypto/Makefile.am
+++ b/crypto/Makefile.am
@@ -81,6 +81,10 @@ if !HAVE_ASPRINTF
81libcompat_la_SOURCES += compat/bsd-asprintf.c 81libcompat_la_SOURCES += compat/bsd-asprintf.c
82endif 82endif
83 83
84if !HAVE_GETPAGESIZE
85libcompat_la_SOURCES += compat/getpagesize.c
86endif
87
84if !HAVE_INET_PTON 88if !HAVE_INET_PTON
85libcompat_la_SOURCES += compat/inet_pton.c 89libcompat_la_SOURCES += compat/inet_pton.c
86endif 90endif
@@ -93,6 +97,10 @@ if !HAVE_REALLOCARRAY
93libcompat_la_SOURCES += compat/reallocarray.c 97libcompat_la_SOURCES += compat/reallocarray.c
94endif 98endif
95 99
100if !HAVE_RECALLOCARRAY
101libcompat_la_SOURCES += compat/recallocarray.c
102endif
103
96if !HAVE_TIMINGSAFE_MEMCMP 104if !HAVE_TIMINGSAFE_MEMCMP
97libcompat_la_SOURCES += compat/timingsafe_memcmp.c 105libcompat_la_SOURCES += compat/timingsafe_memcmp.c
98endif 106endif
diff --git a/crypto/compat/getpagesize.c b/crypto/compat/getpagesize.c
new file mode 100644
index 0000000..098efa9
--- /dev/null
+++ b/crypto/compat/getpagesize.c
@@ -0,0 +1,18 @@
1/* $OpenBSD$ */
2
3#include <unistd.h>
4
5#ifdef _MSC_VER
6#include <windows.h>
7#endif
8
9int
10getpagesize(void) {
11#ifdef _MSC_VER
12 SYSTEM_INFO system_info;
13 GetSystemInfo(&system_info);
14 return system_info.dwPageSize;
15#else
16 return sysconf(_SC_PAGESIZE);
17#endif
18}
diff --git a/include/compat/stdlib.h b/include/compat/stdlib.h
index 781be77..11f82ba 100644
--- a/include/compat/stdlib.h
+++ b/include/compat/stdlib.h
@@ -29,6 +29,10 @@ uint32_t arc4random_uniform(uint32_t upper_bound);
29void *reallocarray(void *, size_t, size_t); 29void *reallocarray(void *, size_t, size_t);
30#endif 30#endif
31 31
32#ifndef HAVE_RECALLOCARRAY
33void *recallocarray(void *, size_t, size_t, size_t);
34#endif
35
32#ifndef HAVE_STRTONUM 36#ifndef HAVE_STRTONUM
33long long strtonum(const char *nptr, long long minval, 37long long strtonum(const char *nptr, long long minval,
34 long long maxval, const char **errstr); 38 long long maxval, const char **errstr);
diff --git a/include/compat/unistd.h b/include/compat/unistd.h
index b37a2f6..d596043 100644
--- a/include/compat/unistd.h
+++ b/include/compat/unistd.h
@@ -39,6 +39,10 @@ int getentropy(void *buf, size_t buflen);
39#endif 39#endif
40#endif 40#endif
41 41
42#ifndef HAVE_GETPAGESIZE
43int getpagesize(void);
44#endif
45
42#define pledge(request, paths) 0 46#define pledge(request, paths) 0
43 47
44#ifndef HAVE_PIPE2 48#ifndef HAVE_PIPE2
diff --git a/m4/check-libc.m4 b/m4/check-libc.m4
index 53ffce6..f9ddf73 100644
--- a/m4/check-libc.m4
+++ b/m4/check-libc.m4
@@ -2,15 +2,18 @@ AC_DEFUN([CHECK_LIBC_COMPAT], [
2# Check for libc headers 2# Check for libc headers
3AC_CHECK_HEADERS([err.h readpassphrase.h]) 3AC_CHECK_HEADERS([err.h readpassphrase.h])
4# Check for general libc functions 4# Check for general libc functions
5AC_CHECK_FUNCS([asprintf inet_ntop inet_pton memmem readpassphrase]) 5AC_CHECK_FUNCS([asprintf getpagesize inet_ntop inet_pton memmem readpassphrase])
6AC_CHECK_FUNCS([reallocarray strlcat strlcpy strndup strnlen strsep strtonum]) 6AC_CHECK_FUNCS([reallocarray recallocarray])
7AC_CHECK_FUNCS([strlcat strlcpy strndup strnlen strsep strtonum])
7AC_CHECK_FUNCS([timegm _mkgmtime]) 8AC_CHECK_FUNCS([timegm _mkgmtime])
8AM_CONDITIONAL([HAVE_ASPRINTF], [test "x$ac_cv_func_asprintf" = xyes]) 9AM_CONDITIONAL([HAVE_ASPRINTF], [test "x$ac_cv_func_asprintf" = xyes])
10AM_CONDITIONAL([HAVE_GETPAGESIZE], [test "x$ac_cv_func_getpagesize" = xyes])
9AM_CONDITIONAL([HAVE_INET_NTOP], [test "x$ac_cv_func_inet_ntop" = xyes]) 11AM_CONDITIONAL([HAVE_INET_NTOP], [test "x$ac_cv_func_inet_ntop" = xyes])
10AM_CONDITIONAL([HAVE_INET_PTON], [test "x$ac_cv_func_inet_pton" = xyes]) 12AM_CONDITIONAL([HAVE_INET_PTON], [test "x$ac_cv_func_inet_pton" = xyes])
11AM_CONDITIONAL([HAVE_MEMMEM], [test "x$ac_cv_func_memmem" = xyes]) 13AM_CONDITIONAL([HAVE_MEMMEM], [test "x$ac_cv_func_memmem" = xyes])
12AM_CONDITIONAL([HAVE_READPASSPHRASE], [test "x$ac_cv_func_readpassphrase" = xyes]) 14AM_CONDITIONAL([HAVE_READPASSPHRASE], [test "x$ac_cv_func_readpassphrase" = xyes])
13AM_CONDITIONAL([HAVE_REALLOCARRAY], [test "x$ac_cv_func_reallocarray" = xyes]) 15AM_CONDITIONAL([HAVE_REALLOCARRAY], [test "x$ac_cv_func_reallocarray" = xyes])
16AM_CONDITIONAL([HAVE_RECALLOCARRAY], [test "x$ac_cv_func_recallocarray" = xyes])
14AM_CONDITIONAL([HAVE_STRLCAT], [test "x$ac_cv_func_strlcat" = xyes]) 17AM_CONDITIONAL([HAVE_STRLCAT], [test "x$ac_cv_func_strlcat" = xyes])
15AM_CONDITIONAL([HAVE_STRLCPY], [test "x$ac_cv_func_strlcpy" = xyes]) 18AM_CONDITIONAL([HAVE_STRLCPY], [test "x$ac_cv_func_strlcpy" = xyes])
16AM_CONDITIONAL([HAVE_STRNDUP], [test "x$ac_cv_func_strndup" = xyes]) 19AM_CONDITIONAL([HAVE_STRNDUP], [test "x$ac_cv_func_strndup" = xyes])
@@ -173,6 +176,9 @@ fi
173if test "x$ac_cv_func_reallocarray" = "xno" ; then 176if test "x$ac_cv_func_reallocarray" = "xno" ; then
174 echo reallocarray >> $crypto_p_sym 177 echo reallocarray >> $crypto_p_sym
175fi 178fi
179if test "x$ac_cv_func_recallocarray" = "xno" ; then
180 echo recallocarray >> $crypto_p_sym
181fi
176if test "x$ac_cv_func_strlcat" = "xno" ; then 182if test "x$ac_cv_func_strlcat" = "xno" ; then
177 echo strlcat >> $crypto_p_sym 183 echo strlcat >> $crypto_p_sym
178fi 184fi
diff --git a/update.sh b/update.sh
index dbb9b60..6fb1da7 100755
--- a/update.sh
+++ b/update.sh
@@ -78,6 +78,7 @@ for i in crypto/compat libtls-standalone/compat; do
78 $libc_src/crypt/chacha_private.h \ 78 $libc_src/crypt/chacha_private.h \
79 $libc_src/net/inet_pton.c \ 79 $libc_src/net/inet_pton.c \
80 $libc_src/stdlib/reallocarray.c \ 80 $libc_src/stdlib/reallocarray.c \
81 $libc_src/stdlib/recallocarray.c \
81 $libc_src/string/explicit_bzero.c \ 82 $libc_src/string/explicit_bzero.c \
82 $libc_src/string/strcasecmp.c \ 83 $libc_src/string/strcasecmp.c \
83 $libc_src/string/strlcpy.c \ 84 $libc_src/string/strlcpy.c \