diff --git a/chacha.c b/chacha.c index 729aa03db..9d79b661c 100644 --- a/chacha.c +++ b/chacha.c @@ -48,8 +48,8 @@ typedef struct chacha_ctx chacha_ctx; a = PLUS(a,b); d = ROTATE(XOR(d,a), 8); \ c = PLUS(c,d); b = ROTATE(XOR(b,c), 7); -static const char sigma[16] = "expand 32-byte k"; -static const char tau[16] = "expand 16-byte k"; +static const char __attribute__ ((__nonstring__)) sigma[16] = "expand 32-byte k"; +static const char __attribute__ ((__nonstring__)) tau[16] = "expand 16-byte k"; void chacha_keysetup(chacha_ctx *x,const u8 *k,u32 kbits) diff --git a/configure.ac b/configure.ac index 831dd85b8..a8e9df66b 100644 --- a/configure.ac +++ b/configure.ac @@ -358,6 +358,19 @@ AC_COMPILE_IFELSE( [ AC_MSG_RESULT([no]) ] ) +saved_CFLAGS="$CFLAGS" +CFLAGS="$CFLAGS -Werror" +AC_MSG_CHECKING([if compiler supports __nonstring__ attribute on char arrays]) +AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([[#include ]], + [[ char __attribute__ ((__nonstring__)) h[5] = "hello"; return h[0]!='h'; ]])], + [ AC_MSG_RESULT([yes]) + AC_DEFINE(HAVE_ATTRIBUTE__NONSTRING__, [1], + [compiler supports nonstring attribute]) ], + [ AC_MSG_RESULT([no]) ] +) +CFLAGS="$saved_CFLAGS" + if test "x$no_attrib_nonnull" != "x1" ; then AC_DEFINE([HAVE_ATTRIBUTE__NONNULL__], [1], [Have attribute nonnull]) fi diff --git a/defines.h b/defines.h index 1988b730c..1d5bc0498 100644 --- a/defines.h +++ b/defines.h @@ -604,6 +604,10 @@ struct winsize { # define __nonnull__(x) #endif +#if !defined(HAVE_ATTRIBUTE__NONSTRING__) && !defined(__nonstring__) +# define __nonstring__ +#endif + #ifndef OSSH_ALIGNBYTES #define OSSH_ALIGNBYTES (sizeof(int) - 1) #endif diff --git a/openbsd-compat/bcrypt_pbkdf.c b/openbsd-compat/bcrypt_pbkdf.c index c41c2d68b..33c9ce109 100644 --- a/openbsd-compat/bcrypt_pbkdf.c +++ b/openbsd-compat/bcrypt_pbkdf.c @@ -73,7 +73,7 @@ static void bcrypt_hash(uint8_t *sha2pass, uint8_t *sha2salt, uint8_t *out) { blf_ctx state; - uint8_t ciphertext[BCRYPT_HASHSIZE] = + uint8_t __attribute__ ((__nonstring__)) ciphertext[BCRYPT_HASHSIZE] = "OxychromaticBlowfishSwatDynamite"; uint32_t cdata[BCRYPT_WORDS]; int i;