[glib-networking] GTlsConnection: avoid non-literal format strings



commit e9145a4daf1849055c449560b9f95a2fcb9b1145
Author: Ryan Lortie <desrt desrt ca>
Date:   Sun Dec 8 15:26:15 2013 -0500

    GTlsConnection: avoid non-literal format strings
    
    The error handling in GTlsConnection involved translated format strings
    that were then passed to another function where the arguments were
    applied.  This prevents the C compiler from enforcing restrictions on
    the format string and runs afoul of -Werror=format-nonliteral, breaking
    the build under clang.
    
    Fix it up so that the error handling function takes the format string
    along with the argument and calls g_error_new_valist().  This allows the
    compiler to check that we're getting it right.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=720081

 tls/gnutls/gtlsconnection-gnutls.c |   27 ++++++++++++++++++++-------
 1 files changed, 20 insertions(+), 7 deletions(-)
---
diff --git a/tls/gnutls/gtlsconnection-gnutls.c b/tls/gnutls/gtlsconnection-gnutls.c
index ae81a82..f1a99b3 100644
--- a/tls/gnutls/gtlsconnection-gnutls.c
+++ b/tls/gnutls/gtlsconnection-gnutls.c
@@ -21,6 +21,7 @@
 #include "glib.h"
 
 #include <errno.h>
+#include <stdarg.h>
 #include <gnutls/gnutls.h>
 #include <gnutls/x509.h>
 
@@ -667,10 +668,19 @@ begin_gnutls_io (GTlsConnectionGnutls  *gnutls,
 
 static int
 end_gnutls_io (GTlsConnectionGnutls  *gnutls,
-              GIOCondition           direction,
-              int                    status,
-              const char            *errmsg,
-              GError               **error)
+               GIOCondition           direction,
+               int                    status,
+               GError               **error,
+               const char            *err_fmt,
+               ...) G_GNUC_PRINTF(5, 6);
+
+static int
+end_gnutls_io (GTlsConnectionGnutls  *gnutls,
+               GIOCondition           direction,
+               int                    status,
+               GError               **error,
+               const char            *err_fmt,
+               ...)
 {
   GError *my_error = NULL;
 
@@ -781,8 +791,11 @@ end_gnutls_io (GTlsConnectionGnutls  *gnutls,
 
   if (error)
     {
-      g_set_error (error, G_TLS_ERROR, G_TLS_ERROR_MISC,
-                   errmsg, gnutls_strerror (status));
+      va_list ap;
+
+      va_start (ap, err_fmt);
+      *error = g_error_new_valist (G_TLS_ERROR, G_TLS_ERROR_MISC, err_fmt, ap);
+      va_end (ap);
     }
   return status;
 }
@@ -792,7 +805,7 @@ end_gnutls_io (GTlsConnectionGnutls  *gnutls,
   do {
 
 #define END_GNUTLS_IO(gnutls, direction, ret, errmsg, err)             \
-  } while ((ret = end_gnutls_io (gnutls, direction, ret, errmsg, err)) == GNUTLS_E_AGAIN);
+  } while ((ret = end_gnutls_io (gnutls, direction, ret, err, errmsg, gnutls_strerror (ret))) == 
GNUTLS_E_AGAIN);
 
 gboolean
 g_tls_connection_gnutls_check (GTlsConnectionGnutls  *gnutls,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]