gnunet-svn
[Top][All Lists]
Advanced

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

[libmicrohttpd] branch master updated: base64: added input checking and


From: gnunet
Subject: [libmicrohttpd] branch master updated: base64: added input checking and fixed compiler warnings
Date: Thu, 05 May 2022 14:44:39 +0200

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

karlson2k pushed a commit to branch master
in repository libmicrohttpd.

The following commit(s) were added to refs/heads/master by this push:
     new 1ed1fe5e base64: added input checking and fixed compiler warnings
1ed1fe5e is described below

commit 1ed1fe5e9ead8cda8c19f339f92a924c88fcbdcc
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
AuthorDate: Thu May 5 15:44:29 2022 +0300

    base64: added input checking and fixed compiler warnings
---
 src/microhttpd/base64.c | 36 +++++++++++++++++++++++++++++-------
 src/microhttpd/base64.h |  4 +---
 2 files changed, 30 insertions(+), 10 deletions(-)

diff --git a/src/microhttpd/base64.c b/src/microhttpd/base64.c
index d7d1ec92..1f07cd7e 100644
--- a/src/microhttpd/base64.c
+++ b/src/microhttpd/base64.c
@@ -5,7 +5,20 @@
  * @file base64.c
  * @brief This code implements the BASE64 algorithm
  * @author Matthieu Speder
+ * @author Karlson2k (Evgeny Grin): fixes and improvements
  */
+#include "mhd_options.h"
+#include <stdio.h>
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif /* HAVE_STDLIB_H */
+#include <string.h>
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#ifdef HAVE_STDDEF_H
+#include <stddef.h>
+#endif /* HAVE_STDDEF_H */
 #include "base64.h"
 
 static const char base64_digits[] =
@@ -24,18 +37,19 @@ static const char base64_digits[] =
 
 
 char *
-BASE64Decode (const char*src)
+BASE64Decode (const char *src)
 {
   size_t in_len = strlen (src);
-  char*dest;
-  char*result;
+  unsigned char *dest;
+  char *result;
 
   if (in_len % 4)
   {
     /* Wrong base64 string length */
     return NULL;
   }
-  result = dest = malloc (in_len / 4 * 3 + 1);
+  dest = (unsigned char *) malloc (in_len / 4 * 3 + 1);
+  result = (char *) dest;
   if (NULL == result)
     return NULL; /* out of memory */
   while (*src)
@@ -44,13 +58,21 @@ BASE64Decode (const char*src)
     char b = base64_digits[(unsigned char) *(src++)];
     char c = base64_digits[(unsigned char) *(src++)];
     char d = base64_digits[(unsigned char) *(src++)];
-    *(dest++) = (a << 2) | ((b & 0x30) >> 4);
+    if (((char) -1 == a) || (0 == a) || (0 == b) || (0 == c) || (0 == d))
+    {
+      free (result);
+      return NULL;
+    }
+    *(dest++) = (unsigned char) (((unsigned char) a) << 2)
+                | (unsigned char) ((((unsigned char) b) & 0x30) >> 4);
     if (c == (char) -1)
       break;
-    *(dest++) = ((b & 0x0f) << 4) | ((c & 0x3c) >> 2);
+    *(dest++) = (unsigned char) ((((unsigned char) b) & 0x0f) << 4)
+                | (unsigned char) ((((unsigned char) c) & 0x3c) >> 2);
     if (d == (char) -1)
       break;
-    *(dest++) = ((c & 0x03) << 6) | d;
+    *(dest++) = (unsigned char) ((((unsigned char) c) & 0x03) << 6)
+                | ((unsigned char) d);
   }
   *dest = 0;
   return result;
diff --git a/src/microhttpd/base64.h b/src/microhttpd/base64.h
index 65042c0b..a489dc69 100644
--- a/src/microhttpd/base64.h
+++ b/src/microhttpd/base64.h
@@ -9,9 +9,7 @@
 #ifndef BASE64_H
 #define BASE64_H
 
-#include "platform.h"
-
 char *
-BASE64Decode (const char*src);
+BASE64Decode (const char *src);
 
 #endif /* !BASE64_H */

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

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