[openssh-commits] [openssh] 01/02: use nonnull attribute when available

git+noreply at mindrot.org git+noreply at mindrot.org
Sun Mar 29 16:44:03 AEDT 2026


This is an automated email from the git hooks/post-receive script.

djm pushed a commit to branch master
in repository openssh.

commit c90f46b6230826cdadacd6c32b62b0f8106a09da
Author: Damien Miller <djm at mindrot.org>
AuthorDate: Sun Mar 29 16:42:33 2026 +1100

    use nonnull attribute when available
    
    Set this attribute on a few string to avoid compiler warnings from
    -Wunterminated-string-initialization warnings in recent gcc.
---
 chacha.c                      |  4 ++--
 configure.ac                  | 13 +++++++++++++
 defines.h                     |  4 ++++
 openbsd-compat/bcrypt_pbkdf.c |  2 +-
 4 files changed, 20 insertions(+), 3 deletions(-)

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 <stdlib.h>]],
+    [[ 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;

-- 
To stop receiving notification emails like this one, please contact
djm at mindrot.org.


More information about the openssh-commits mailing list