aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrent Cook <bcook@openbsd.org>2014-10-29 15:44:36 -0500
committerBrent Cook <bcook@openbsd.org>2014-10-30 19:15:11 -0500
commita4cc953911a745d6e769a03cbe6442ee2fc27cbd (patch)
tree8c26006db95beb6249b755e108ee1aa317e742bd
parent727bccd093eaeac853ac84c7b6f31e67e452cde9 (diff)
downloadportable-a4cc953911a745d6e769a03cbe6442ee2fc27cbd.tar.gz
portable-a4cc953911a745d6e769a03cbe6442ee2fc27cbd.tar.bz2
portable-a4cc953911a745d6e769a03cbe6442ee2fc27cbd.zip
Improve and simplify function and header detection logic.
Simplify autoconf checks by using AC_CHECK_FUNCS/HEADERS. Clarify some ambiguous dependencies around strnlen/strndup. Unconditionally enable pidwraptest for all arc4random implementations. Remove HAVE_VASPRINTF conditional, since asprintf requires vasprintf. ok @doug
-rw-r--r--apps/Makefile.am.tpl2
-rw-r--r--configure.ac97
-rw-r--r--crypto/Makefile.am.tpl25
-rw-r--r--crypto/compat/bsd-asprintf.c4
-rw-r--r--include/stdio.h2
-rw-r--r--include/stdlib.h6
-rw-r--r--include/string.h17
-rw-r--r--include/unistd.h4
-rw-r--r--tests/Makefile.am.tpl4
-rwxr-xr-xupdate.sh3
10 files changed, 52 insertions, 112 deletions
diff --git a/apps/Makefile.am.tpl b/apps/Makefile.am.tpl
index 9bc7b2e..433fca2 100644
--- a/apps/Makefile.am.tpl
+++ b/apps/Makefile.am.tpl
@@ -10,6 +10,6 @@ openssl_LDADD += $(top_builddir)/crypto/libcrypto.la
10openssl_SOURCES = 10openssl_SOURCES =
11noinst_HEADERS = 11noinst_HEADERS =
12 12
13if NO_STRTONUM 13if !HAVE_STRTONUM
14openssl_SOURCES += strtonum.c 14openssl_SOURCES += strtonum.c
15endif 15endif
diff --git a/configure.ac b/configure.ac
index eca3134..6ae06a1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -58,75 +58,26 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
58) 58)
59CFLAGS="$save_cflags $AM_CFLAGS" 59CFLAGS="$save_cflags $AM_CFLAGS"
60 60
61AC_CHECK_FUNC(strlcpy, 61AC_CHECK_FUNCS([arc4random_buf asprintf explicit_bzero funopen getauxval])
62 AM_CONDITIONAL(NO_STRLCPY, false), 62AC_CHECK_FUNCS([getentropy issetugid memmem reallocarray])
63 AC_DEFINE(NO_STRLCPY) 63AC_CHECK_FUNCS([strlcat strlcpy strndup strnlen strtonum])
64 AM_CONDITIONAL(NO_STRLCPY, true)) 64AC_CHECK_FUNCS([timingsafe_bcmp timingsafe_memcmp])
65 65
66AC_CHECK_FUNC(strlcat, 66# Share test results with automake
67 AM_CONDITIONAL(NO_STRLCAT, false), 67AM_CONDITIONAL([HAVE_ARC4RANDOM_BUF], [test "x$ac_cv_func_arc4random_buf" = xyes])
68 AC_DEFINE(NO_STRLCAT) 68AM_CONDITIONAL([HAVE_ASPRINTF], [test "x$ac_cv_func_asprintf" = xyes])
69 AM_CONDITIONAL(NO_STRLCAT, true)) 69AM_CONDITIONAL([HAVE_EXPLICIT_BZERO], [test "x$ac_cv_func_explicit_bzero" = xyes])
70 70AM_CONDITIONAL([HAVE_GETENTROPY], [test "x$ac_cv_func_getentropy" = xyes])
71AC_CHECK_FUNC(strndup, 71AM_CONDITIONAL([HAVE_ISSETUGID], [test "x$ac_cv_func_issetugid" = xyes])
72 AM_CONDITIONAL(NO_STRNDUP, false), 72AM_CONDITIONAL([HAVE_MEMMEM], [test "x$ac_cv_func_memmem" = xyes])
73 AC_DEFINE(NO_STRNDUP) 73AM_CONDITIONAL([HAVE_REALLOCARRAY], [test "x$ac_cv_func_reallocarray" = xyes])
74 AM_CONDITIONAL(NO_STRNDUP, true)) 74AM_CONDITIONAL([HAVE_STRLCAT], [test "x$ac_cv_func_strlcat" = xyes])
75 75AM_CONDITIONAL([HAVE_STRLCPY], [test "x$ac_cv_func_strlcpy" = xyes])
76AC_CHECK_FUNC(strnlen, 76AM_CONDITIONAL([HAVE_STRNDUP], [test "x$ac_cv_func_strndup" = xyes])
77 AM_CONDITIONAL(NO_STRNLEN, false), 77AM_CONDITIONAL([HAVE_STRNLEN], [test "x$ac_cv_func_strnlen" = xyes])
78 AC_DEFINE(NO_STRNLEN) 78AM_CONDITIONAL([HAVE_STRTONUM], [test "x$ac_cv_func_strtonum" = xyes])
79 AM_CONDITIONAL(NO_STRNLEN, true)) 79AM_CONDITIONAL([HAVE_TIMINGSAFE_BCMP], [test "x$ac_cv_func_timingsafe_bcmp" = xyes])
80 80AM_CONDITIONAL([HAVE_TIMINGSAFE_MEMCMP], [test "x$ac_cv_func_timingsafe_memcmp" = xyes])
81AC_CHECK_FUNC(asprintf,
82 AM_CONDITIONAL(NO_ASPRINTF, false),
83 AC_DEFINE(NO_ASPRINTF)
84 AM_CONDITIONAL(NO_ASPRINTF, true))
85
86AC_CHECK_FUNC(reallocarray,
87 AM_CONDITIONAL(NO_REALLOCARRAY, false),
88 AC_DEFINE(NO_REALLOCARRAY)
89 AM_CONDITIONAL(NO_REALLOCARRAY, true))
90
91AC_CHECK_FUNC(timingsafe_bcmp,
92 AM_CONDITIONAL(NO_TIMINGSAFE_BCMP, false),
93 AC_DEFINE(NO_TIMINGSAFE_BCMP)
94 AM_CONDITIONAL(NO_TIMINGSAFE_BCMP, true))
95
96AC_CHECK_FUNC(timingsafe_memcmp,
97 AM_CONDITIONAL(NO_TIMINGSAFE_MEMCMP, false),
98 AC_DEFINE(NO_TIMINGSAFE_MEMCMP)
99 AM_CONDITIONAL(NO_TIMINGSAFE_MEMCMP, true))
100
101AC_CHECK_FUNC(arc4random_buf,
102 AM_CONDITIONAL(NO_ARC4RANDOM_BUF, false),
103 AC_DEFINE(NO_ARC4RANDOM_BUF)
104 AM_CONDITIONAL(NO_ARC4RANDOM_BUF, true))
105
106AC_CHECK_FUNC(getentropy,
107 AM_CONDITIONAL(NO_GETENTROPY, false),
108 AC_DEFINE(NO_GETENTROPY)
109 AM_CONDITIONAL(NO_GETENTROPY, true))
110
111AC_CHECK_FUNC(issetugid,
112 AM_CONDITIONAL(NO_ISSETUGID, false),
113 AC_DEFINE(NO_ISSETUGID)
114 AM_CONDITIONAL(NO_ISSETUGID, true))
115
116AC_CHECK_FUNC(strtonum,
117 AM_CONDITIONAL(NO_STRTONUM, false),
118 AC_DEFINE(NO_STRTONUM)
119 AM_CONDITIONAL(NO_STRTONUM, true))
120
121AC_CHECK_FUNC(memmem,
122 AM_CONDITIONAL(NO_MEMMEM, false),
123 AC_DEFINE(NO_MEMMEM)
124 AM_CONDITIONAL(NO_MEMMEM, true))
125
126AC_CHECK_FUNC(explicit_bzero,
127 AM_CONDITIONAL(NO_EXPLICIT_BZERO, false),
128 AC_DEFINE(NO_EXPLICIT_BZERO)
129 AM_CONDITIONAL(NO_EXPLICIT_BZERO, true))
130 81
131AC_CACHE_CHECK([whether va_copy exists], ac_cv_have_va_copy, [ 82AC_CACHE_CHECK([whether va_copy exists], ac_cv_have_va_copy, [
132 AC_LINK_IFELSE([AC_LANG_PROGRAM([[ 83 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
@@ -153,13 +104,7 @@ if test "x$ac_cv_have___va_copy" = "xyes" ; then
153 AC_DEFINE([HAVE___VA_COPY], [1], [Define if __va_copy exists]) 104 AC_DEFINE([HAVE___VA_COPY], [1], [Define if __va_copy exists])
154fi 105fi
155 106
156AC_CHECK_FUNC(getauxval, AC_DEFINE(HAVE_GETAUXVAL)) 107AC_CHECK_HEADERS([sys/sysctl.h err.h])
157
158AC_CHECK_FUNC(funopen, AC_DEFINE(HAVE_FUNOPEN))
159
160AC_CHECK_HEADER(sys/sysctl.h, AC_DEFINE(HAVE_SYS_SYSCTL_H))
161
162AC_CHECK_HEADER(err.h, AC_DEFINE(HAVE_ERR_H))
163 108
164AC_ARG_WITH([openssldir], 109AC_ARG_WITH([openssldir],
165 AS_HELP_STRING([--with-openssldir], [Set the default openssl directory]), 110 AS_HELP_STRING([--with-openssldir], [Set the default openssl directory]),
diff --git a/crypto/Makefile.am.tpl b/crypto/Makefile.am.tpl
index 04ff7f7..0ace78a 100644
--- a/crypto/Makefile.am.tpl
+++ b/crypto/Makefile.am.tpl
@@ -16,7 +16,7 @@ noinst_LTLIBRARIES = libcompat.la libcompatnoopt.la
16libcompatnoopt_la_CFLAGS = -O0 16libcompatnoopt_la_CFLAGS = -O0
17libcompatnoopt_la_SOURCES = 17libcompatnoopt_la_SOURCES =
18 18
19if NO_EXPLICIT_BZERO 19if !HAVE_EXPLICIT_BZERO
20libcompatnoopt_la_SOURCES += compat/explicit_bzero.c 20libcompatnoopt_la_SOURCES += compat/explicit_bzero.c
21endif 21endif
22 22
@@ -25,41 +25,42 @@ libcompat_la_CFLAGS = $(CFLAGS) $(USER_CFLAGS)
25libcompat_la_SOURCES = 25libcompat_la_SOURCES =
26libcompat_la_LIBADD = $(PLATFORM_LDADD) 26libcompat_la_LIBADD = $(PLATFORM_LDADD)
27 27
28if NO_STRLCAT 28if !HAVE_STRLCAT
29libcompat_la_SOURCES += compat/strlcat.c 29libcompat_la_SOURCES += compat/strlcat.c
30endif 30endif
31 31
32if NO_STRLCPY 32if !HAVE_STRLCPY
33libcompat_la_SOURCES += compat/strlcpy.c 33libcompat_la_SOURCES += compat/strlcpy.c
34endif 34endif
35 35
36if NO_STRNDUP 36if !HAVE_STRNDUP
37libcompat_la_SOURCES += compat/strndup.c 37libcompat_la_SOURCES += compat/strndup.c
38if NO_STRNLEN 38# the only user of strnlen is strndup, so only build it if needed
39if !HAVE_STRNLEN
39libcompat_la_SOURCES += compat/strnlen.c 40libcompat_la_SOURCES += compat/strnlen.c
40endif 41endif
41endif 42endif
42 43
43if NO_ASPRINTF 44if !HAVE_ASPRINTF
44libcompat_la_SOURCES += compat/bsd-asprintf.c 45libcompat_la_SOURCES += compat/bsd-asprintf.c
45endif 46endif
46 47
47if NO_REALLOCARRAY 48if !HAVE_REALLOCARRAY
48libcompat_la_SOURCES += compat/reallocarray.c 49libcompat_la_SOURCES += compat/reallocarray.c
49endif 50endif
50 51
51if NO_TIMINGSAFE_MEMCMP 52if !HAVE_TIMINGSAFE_MEMCMP
52libcompat_la_SOURCES += compat/timingsafe_memcmp.c 53libcompat_la_SOURCES += compat/timingsafe_memcmp.c
53endif 54endif
54 55
55if NO_TIMINGSAFE_BCMP 56if !HAVE_TIMINGSAFE_BCMP
56libcompat_la_SOURCES += compat/timingsafe_bcmp.c 57libcompat_la_SOURCES += compat/timingsafe_bcmp.c
57endif 58endif
58 59
59if NO_ARC4RANDOM_BUF 60if !HAVE_ARC4RANDOM_BUF
60libcompat_la_SOURCES += compat/arc4random.c 61libcompat_la_SOURCES += compat/arc4random.c
61 62
62if NO_GETENTROPY 63if !HAVE_GETENTROPY
63if HOST_LINUX 64if HOST_LINUX
64libcompat_la_SOURCES += compat/getentropy_linux.c 65libcompat_la_SOURCES += compat/getentropy_linux.c
65endif 66endif
@@ -76,7 +77,7 @@ endif
76 77
77endif 78endif
78 79
79if NO_ISSETUGID 80if !HAVE_ISSETUGID
80if HOST_LINUX 81if HOST_LINUX
81libcompat_la_SOURCES += compat/issetugid_linux.c 82libcompat_la_SOURCES += compat/issetugid_linux.c
82endif 83endif
diff --git a/crypto/compat/bsd-asprintf.c b/crypto/compat/bsd-asprintf.c
index 8ccfa22..3728bc5 100644
--- a/crypto/compat/bsd-asprintf.c
+++ b/crypto/compat/bsd-asprintf.c
@@ -17,7 +17,7 @@
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */ 18 */
19 19
20#ifndef HAVE_VASPRINTF 20#ifndef HAVE_ASPRINTF
21 21
22#include <errno.h> 22#include <errno.h>
23#include <limits.h> /* for INT_MAX */ 23#include <limits.h> /* for INT_MAX */
@@ -80,9 +80,7 @@ fail:
80 errno = ENOMEM; 80 errno = ENOMEM;
81 return (-1); 81 return (-1);
82} 82}
83#endif
84 83
85#ifndef HAVE_ASPRINTF
86int asprintf(char **str, const char *fmt, ...) 84int asprintf(char **str, const char *fmt, ...)
87{ 85{
88 va_list ap; 86 va_list ap;
diff --git a/include/stdio.h b/include/stdio.h
index fffa170..4a40f6a 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -3,7 +3,7 @@
3#ifndef LIBCRYPTOCOMPAT_STDIO_H 3#ifndef LIBCRYPTOCOMPAT_STDIO_H
4#define LIBCRYPTOCOMPAT_STDIO_H 4#define LIBCRYPTOCOMPAT_STDIO_H
5 5
6#ifdef NO_ASPRINTF 6#ifndef HAVE_ASPRINTF
7#include <stdarg.h> 7#include <stdarg.h>
8int vasprintf(char **str, const char *fmt, va_list ap); 8int vasprintf(char **str, const char *fmt, va_list ap);
9int asprintf(char **str, const char *fmt, ...); 9int asprintf(char **str, const char *fmt, ...);
diff --git a/include/stdlib.h b/include/stdlib.h
index c314f38..1a1cb6c 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -7,16 +7,16 @@
7#include <sys/time.h> 7#include <sys/time.h>
8#include <stdint.h> 8#include <stdint.h>
9 9
10#ifdef NO_ARC4RANDOM_BUF 10#ifndef HAVE_ARC4RANDOM_BUF
11uint32_t arc4random(void); 11uint32_t arc4random(void);
12void arc4random_buf(void *_buf, size_t n); 12void arc4random_buf(void *_buf, size_t n);
13#endif 13#endif
14 14
15#ifdef NO_REALLOCARRAY 15#ifndef HAVE_REALLOCARRAY
16void *reallocarray(void *, size_t, size_t); 16void *reallocarray(void *, size_t, size_t);
17#endif 17#endif
18 18
19#ifdef NO_STRTONUM 19#ifndef HAVE_STRTONUM
20long long strtonum(const char *nptr, long long minval, 20long long strtonum(const char *nptr, long long minval,
21 long long maxval, const char **errstr); 21 long long maxval, const char **errstr);
22#endif 22#endif
diff --git a/include/string.h b/include/string.h
index f092477..47ada28 100644
--- a/include/string.h
+++ b/include/string.h
@@ -12,34 +12,35 @@
12#include <strings.h> 12#include <strings.h>
13#endif 13#endif
14 14
15#ifdef NO_STRLCPY 15#ifndef HAVE_STRLCPY
16size_t strlcpy(char *dst, const char *src, size_t siz); 16size_t strlcpy(char *dst, const char *src, size_t siz);
17#endif 17#endif
18 18
19#ifdef NO_STRLCAT 19#ifndef HAVE_STRLCAT
20size_t strlcat(char *dst, const char *src, size_t siz); 20size_t strlcat(char *dst, const char *src, size_t siz);
21#endif 21#endif
22 22
23#ifdef NO_STRNDUP 23#ifndef HAVE_STRNDUP
24char * strndup(const char *str, size_t maxlen); 24char * strndup(const char *str, size_t maxlen);
25#ifdef NO_STRNLEN 25/* the only user of strnlen is strndup, so only build it if needed */
26#ifndef HAVE_STRNLEN
26size_t strnlen(const char *str, size_t maxlen); 27size_t strnlen(const char *str, size_t maxlen);
27#endif 28#endif
28#endif 29#endif
29 30
30#ifdef NO_EXPLICIT_BZERO 31#ifndef HAVE_EXPLICIT_BZERO
31void explicit_bzero(void *, size_t); 32void explicit_bzero(void *, size_t);
32#endif 33#endif
33 34
34#ifdef NO_TIMINGSAFE_BCMP 35#ifndef HAVE_TIMINGSAFE_BCMP
35int timingsafe_bcmp(const void *b1, const void *b2, size_t n); 36int timingsafe_bcmp(const void *b1, const void *b2, size_t n);
36#endif 37#endif
37 38
38#ifdef NO_TIMINGSAFE_MEMCMP 39#ifndef HAVE_TIMINGSAFE_MEMCMP
39int timingsafe_memcmp(const void *b1, const void *b2, size_t len); 40int timingsafe_memcmp(const void *b1, const void *b2, size_t len);
40#endif 41#endif
41 42
42#ifdef NO_MEMMEM 43#ifndef HAVE_MEMMEM
43void * memmem(const void *big, size_t big_len, const void *little, 44void * memmem(const void *big, size_t big_len, const void *little,
44 size_t little_len); 45 size_t little_len);
45#endif 46#endif
diff --git a/include/unistd.h b/include/unistd.h
index 037b11a..38caeb1 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -3,11 +3,11 @@
3#ifndef LIBCRYPTOCOMPAT_UNISTD_H 3#ifndef LIBCRYPTOCOMPAT_UNISTD_H
4#define LIBCRYPTOCOMPAT_UNISTD_H 4#define LIBCRYPTOCOMPAT_UNISTD_H
5 5
6#ifdef NO_GETENTROPY 6#ifndef HAVE_GETENTROPY
7int getentropy(void *buf, size_t buflen); 7int getentropy(void *buf, size_t buflen);
8#endif 8#endif
9 9
10#ifdef NO_ISSETUGID 10#ifndef HAVE_ISSETUGID
11int issetugid(void); 11int issetugid(void);
12#endif 12#endif
13 13
diff --git a/tests/Makefile.am.tpl b/tests/Makefile.am.tpl
index 52df298..5a760da 100644
--- a/tests/Makefile.am.tpl
+++ b/tests/Makefile.am.tpl
@@ -9,7 +9,3 @@ LDADD += $(top_builddir)/crypto/libcrypto.la
9TESTS = 9TESTS =
10check_PROGRAMS = 10check_PROGRAMS =
11EXTRA_DIST = 11EXTRA_DIST =
12
13if !NO_ARC4RANDOM_BUF
14TESTS += pidwraptest.sh
15endif
diff --git a/update.sh b/update.sh
index 166f609..97af0ff 100755
--- a/update.sh
+++ b/update.sh
@@ -305,7 +305,6 @@ test_drivers=(
305# disabled by-default tests 305# disabled by-default tests
306tests_disabled=( 306tests_disabled=(
307 biotest 307 biotest
308 pidwraptest
309) 308)
310$CP $libc_src/string/memmem.c tests/ 309$CP $libc_src/string/memmem.c tests/
311(cd tests 310(cd tests
@@ -319,7 +318,7 @@ $CP $libc_src/string/memmem.c tests/
319 echo "check_PROGRAMS += $TEST" >> Makefile.am 318 echo "check_PROGRAMS += $TEST" >> Makefile.am
320 echo "${TEST}_SOURCES = $i" >> Makefile.am 319 echo "${TEST}_SOURCES = $i" >> Makefile.am
321 done 320 done
322 echo "if NO_MEMMEM" >> Makefile.am 321 echo "if !HAVE_MEMMEM" >> Makefile.am
323 echo "explicit_bzero_SOURCES += memmem.c" >> Makefile.am 322 echo "explicit_bzero_SOURCES += memmem.c" >> Makefile.am
324 echo "endif" >> Makefile.am 323 echo "endif" >> Makefile.am
325) 324)