From a2333584170a565adf4f209586772ef8053b10b8 Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Thu, 14 Jul 2016 10:59:09 +1000 Subject: Add compat code for missing wcwidth. If we don't have wcwidth force fallback implementations of nl_langinfo and mbtowc. Based on advice from Ingo Schwarze. --- openbsd-compat/openbsd-compat.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'openbsd-compat/openbsd-compat.h') diff --git a/openbsd-compat/openbsd-compat.h b/openbsd-compat/openbsd-compat.h index 8cc8a11b7..997541e43 100644 --- a/openbsd-compat/openbsd-compat.h +++ b/openbsd-compat/openbsd-compat.h @@ -36,6 +36,8 @@ #include +#include /* for wchar_t */ + /* OpenBSD function replacements */ #include "base64.h" #include "sigact.h" @@ -231,6 +233,22 @@ long long strtonum(const char *, long long, long long, const char **); # define mblen(x, y) (1) #endif +#ifndef HAVE_WCWIDTH +# define wcwidth(x) (((x) >= 0x20 && (x) <= 0x7e) ? 1 : -1) +/* force our no-op nl_langinfo and mbtowc */ +# undef HAVE_NL_LANGINFO +# undef HAVE_MBTOWC +# undef HAVE_LANGINFO_H +#endif + +#ifndef HAVE_NL_LANGINFO +# define nl_langinfo(x) "" +#endif + +#ifndef HAVE_MBTOWC +int mbtowc(wchar_t *, const char*, size_t); +#endif + #if !defined(HAVE_VASPRINTF) || !defined(HAVE_VSNPRINTF) # include #endif -- cgit v1.2.3 From 5abfb15ced985c340359ae7fb65a625ed3692b3e Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Fri, 15 Jul 2016 14:48:30 +1000 Subject: Move VA_COPY macro into compat header. Some AIX compilers unconditionally undefine va_copy but don't set it back to an internal function, causing link errors. In some compat code we already use VA_COPY instead so move the two existing instances into the shared header and use for sshbuf-getput-basic.c too. Should fix building with at lease some versions of AIX's compiler. bz#2589, ok djm@ --- openbsd-compat/bsd-asprintf.c | 12 ------------ openbsd-compat/bsd-snprintf.c | 12 ------------ openbsd-compat/openbsd-compat.h | 17 +++++++++++++++++ sshbuf-getput-basic.c | 4 ++-- 4 files changed, 19 insertions(+), 26 deletions(-) (limited to 'openbsd-compat/openbsd-compat.h') diff --git a/openbsd-compat/bsd-asprintf.c b/openbsd-compat/bsd-asprintf.c index 3368195d4..7b83448ca 100644 --- a/openbsd-compat/bsd-asprintf.c +++ b/openbsd-compat/bsd-asprintf.c @@ -25,18 +25,6 @@ #include #include -#ifndef VA_COPY -# ifdef HAVE_VA_COPY -# define VA_COPY(dest, src) va_copy(dest, src) -# else -# ifdef HAVE___VA_COPY -# define VA_COPY(dest, src) __va_copy(dest, src) -# else -# define VA_COPY(dest, src) (dest) = (src) -# endif -# endif -#endif - #define INIT_SZ 128 int diff --git a/openbsd-compat/bsd-snprintf.c b/openbsd-compat/bsd-snprintf.c index 23a635989..d95b6a401 100644 --- a/openbsd-compat/bsd-snprintf.c +++ b/openbsd-compat/bsd-snprintf.c @@ -99,18 +99,6 @@ # undef HAVE_VSNPRINTF #endif -#ifndef VA_COPY -# ifdef HAVE_VA_COPY -# define VA_COPY(dest, src) va_copy(dest, src) -# else -# ifdef HAVE___VA_COPY -# define VA_COPY(dest, src) __va_copy(dest, src) -# else -# define VA_COPY(dest, src) (dest) = (src) -# endif -# endif -#endif - #if !defined(HAVE_SNPRINTF) || !defined(HAVE_VSNPRINTF) #include diff --git a/openbsd-compat/openbsd-compat.h b/openbsd-compat/openbsd-compat.h index 997541e43..37d2064cd 100644 --- a/openbsd-compat/openbsd-compat.h +++ b/openbsd-compat/openbsd-compat.h @@ -253,6 +253,23 @@ int mbtowc(wchar_t *, const char*, size_t); # include #endif +/* + * Some platforms unconditionally undefine va_copy() so we define VA_COPY() + * instead. This is known to be the case on at least some configurations of + * AIX with the xlc compiler. + */ +#ifndef VA_COPY +# ifdef HAVE_VA_COPY +# define VA_COPY(dest, src) va_copy(dest, src) +# else +# ifdef HAVE___VA_COPY +# define VA_COPY(dest, src) __va_copy(dest, src) +# else +# define VA_COPY(dest, src) (dest) = (src) +# endif +# endif +#endif + #ifndef HAVE_VASPRINTF int vasprintf(char **, const char *, va_list); #endif diff --git a/sshbuf-getput-basic.c b/sshbuf-getput-basic.c index ad21ae574..74c49be7c 100644 --- a/sshbuf-getput-basic.c +++ b/sshbuf-getput-basic.c @@ -270,7 +270,7 @@ sshbuf_putfv(struct sshbuf *buf, const char *fmt, va_list ap) int r, len; u_char *p; - va_copy(ap2, ap); + VA_COPY(ap2, ap); if ((len = vsnprintf(NULL, 0, fmt, ap2)) < 0) { r = SSH_ERR_INVALID_ARGUMENT; goto out; @@ -280,7 +280,7 @@ sshbuf_putfv(struct sshbuf *buf, const char *fmt, va_list ap) goto out; /* Nothing to do */ } va_end(ap2); - va_copy(ap2, ap); + VA_COPY(ap2, ap); if ((r = sshbuf_reserve(buf, (size_t)len + 1, &p)) < 0) goto out; if ((r = vsnprintf((char *)p, len + 1, fmt, ap2)) != len) { -- cgit v1.2.3