[PATCH gnupg] Fix gcc -Wunterminated-string-initialization warnings.

Collin Funk via Gnupg-devel <[email protected]>
Newsgroups gmane.comp.encryption.gpg.devel
Message-ID <[email protected]>
* common/ksba-io-support.c (ATTR_NONSTRING): New macro.
(bintoasc): Mark with ATTR_NONSTRING.
(has_only_base64): Use memchr since calling strchr on a non-NUL
terminated string is undefined behavior.
* dirmngr/dns.c (DNS_NONSTRING): New macro.
(dns_aaaa_arpa, dns_sshfp_print): Mark a variable with DNS_NONSTRING.

--

GnuPG-bug-id: 7629
Signed-off-by: Collin Funk <[email protected]>
---
 common/ksba-io-support.c | 7 +++++--
 dirmngr/dns.c            | 7 +++++--
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/common/ksba-io-support.c b/common/ksba-io-support.c
index 352485ffa..10419ab20 100644
--- a/common/ksba-io-support.c
+++ b/common/ksba-io-support.c
@@ -51,6 +51,9 @@
   #define LF "\n"
 #endif
 
+#if __GNUC__ >= 8
+# define ATTR_NONSTRING __attribute__ ((__nonstring__))
+#endif
 
 /* Data used by the reader callbacks.  */
 struct reader_cb_parm_s
@@ -134,7 +137,7 @@ struct gnupg_ksba_io_s {
 
 
 /* The base-64 character list */
-static char bintoasc[64] =
+static char bintoasc[64] ATTR_NONSTRING =
        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
        "abcdefghijklmnopqrstuvwxyz"
        "0123456789+/";
@@ -174,7 +177,7 @@ has_only_base64 (const unsigned char *line, int linelen)
     {
       if (*line == '\n' || (linelen > 1 && *line == '\r' && line[1] == '\n'))
           break;
-      if ( !strchr (bintoasc, *line) )
+      if ( !memchr (bintoasc, *line, sizeof (bintoasc)) )
         return 0;
     }
   return 1;  /* yes */
diff --git a/dirmngr/dns.c b/dirmngr/dns.c
index 5c7bb08d8..bfab59f13 100644
--- a/dirmngr/dns.c
+++ b/dirmngr/dns.c
@@ -131,6 +131,9 @@ typedef int socket_fd_t;
 #if __GNUC__
 #define DNS_NOTUSED __attribute__((unused))
 #define DNS_NORETURN __attribute__((__noreturn__))
+#if __GNUC__ >= 8
+#define DNS_NONSTRING __attribute__((__nonstring__))
+#endif
 #else
 #define DNS_NOTUSED
 #define DNS_NORETURN
@@ -3441,7 +3444,7 @@ static int dns_aaaa_cmp0(const void *a, const void *b) {
 }
 
 size_t dns_aaaa_arpa(void *_dst, size_t lim, const struct dns_aaaa *aaaa) {
-	static const unsigned char hex[16] = "0123456789abcdef";
+	static const unsigned char hex[16] DNS_NONSTRING = "0123456789abcdef";
 	struct dns_buf dst = DNS_B_INTO(_dst, lim);
 	unsigned nyble;
 	int i, j;
@@ -4222,7 +4225,7 @@ static int dns_sshfp_cmp0(const void *a, const void *b) {
 
 
 size_t dns_sshfp_print(void *_dst, size_t lim, struct dns_sshfp *fp) {
-	static const unsigned char hex[16] = "0123456789abcdef";
+	static const unsigned char hex[16] DNS_NONSTRING = "0123456789abcdef";
 	struct dns_buf dst = DNS_B_INTO(_dst, lim);
 	size_t i;
 
-- 
2.49.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.