gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r36989 - libmicrohttpd/src/microhttpd


From: gnunet
Subject: [GNUnet-SVN] r36989 - libmicrohttpd/src/microhttpd
Date: Fri, 8 Apr 2016 18:31:05 +0200

Author: Karlson2k
Date: 2016-04-08 18:31:05 +0200 (Fri, 08 Apr 2016)
New Revision: 36989

Modified:
   libmicrohttpd/src/microhttpd/basicauth.c
   libmicrohttpd/src/microhttpd/digestauth.c
Log:
Check result of snprintf() in basicauth.c and digestauth.c, log more errors

Modified: libmicrohttpd/src/microhttpd/basicauth.c
===================================================================
--- libmicrohttpd/src/microhttpd/basicauth.c    2016-04-08 16:31:03 UTC (rev 
36988)
+++ libmicrohttpd/src/microhttpd/basicauth.c    2016-04-08 16:31:05 UTC (rev 
36989)
@@ -117,7 +117,7 @@
                                    const char *realm, 
                                    struct MHD_Response *response) 
 {
-  int ret;
+  int ret, res;
   size_t hlen = strlen(realm) + strlen("Basic realm=\"\"") + 1;
   char *header;
   
@@ -130,18 +130,29 @@
 #endif /* HAVE_MESSAGES */
     return MHD_NO;
   }
-  MHD_snprintf_ (header, 
-           hlen, 
-           "Basic realm=\"%s\"", 
-           realm);
-  ret = MHD_add_response_header (response,
-                                MHD_HTTP_HEADER_WWW_AUTHENTICATE,
-                                header);
+  res = MHD_snprintf_ (header, 
+                       hlen, 
+                       "Basic realm=\"%s\"", 
+                       realm);
+  if (res > 0 && res < hlen)
+    ret = MHD_add_response_header (response,
+                                   MHD_HTTP_HEADER_WWW_AUTHENTICATE,
+                                   header);
+  else
+    ret = MHD_NO;
+
   free(header);
   if (MHD_YES == ret)
     ret = MHD_queue_response (connection, 
                              MHD_HTTP_UNAUTHORIZED, 
                              response);
+  else
+    {
+#ifdef HAVE_MESSAGES
+      MHD_DLOG (connection->daemon,
+                "Failed to add Basic auth header\n");
+#endif /* HAVE_MESSAGES */
+    }
   return ret;
 }
 

Modified: libmicrohttpd/src/microhttpd/digestauth.c
===================================================================
--- libmicrohttpd/src/microhttpd/digestauth.c   2016-04-08 16:31:03 UTC (rev 
36988)
+++ libmicrohttpd/src/microhttpd/digestauth.c   2016-04-08 16:31:05 UTC (rev 
36989)
@@ -822,6 +822,7 @@
                   signal_stale
                   ? ",stale=\"true\""
                   : "");
+  if (hlen > 0)
   {
     char *header;
 
@@ -835,7 +836,7 @@
       return MHD_NO;
     }
 
-    MHD_snprintf_(header,
+    if (MHD_snprintf_(header,
              hlen + 1,
              "Digest realm=\"%s\",qop=\"auth\",nonce=\"%s\",opaque=\"%s\"%s",
              realm,
@@ -843,16 +844,28 @@
              opaque,
              signal_stale
              ? ",stale=\"true\""
-             : "");
-    ret = MHD_add_response_header(response,
+             : "") == hlen)
+      ret = MHD_add_response_header(response,
                                  MHD_HTTP_HEADER_WWW_AUTHENTICATE,
                                  header);
+    else
+      ret = MHD_NO;
     free(header);
   }
+  else
+    ret = MHD_NO;
+
   if (MHD_YES == ret)
     ret = MHD_queue_response(connection,
                             MHD_HTTP_UNAUTHORIZED,
                             response);
+  else
+    {
+#ifdef HAVE_MESSAGES
+      MHD_DLOG (connection->daemon,
+                "Failed to add Digest auth header\n");
+#endif /* HAVE_MESSAGES */
+    }
   return ret;
 }
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]