]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/hash.c
Merge pull request #5621 from zdohnal/cgigetarray-sigsegv
[thirdparty/cups.git] / cups / hash.c
index 061486076ca405978b33941838f0d0c40e1088f4..4fbb443db10cbf2180bb2af6266ed00a177d9a89 100644 (file)
@@ -16,6 +16,7 @@
 #  include <CommonCrypto/CommonDigest.h>
 #elif defined(HAVE_GNUTLS)
 #  include <gnutls/crypto.h>
+#  include "md5-internal.h"
 #else
 #  include "md5-internal.h"
 #endif /* __APPLE__ */
@@ -185,8 +186,24 @@ cupsHashData(const char    *algorithm,     /* I - Algorithm name */
   unsigned char        temp[64];               /* Temporary hash buffer */
   size_t       tempsize = 0;           /* Truncate to this size? */
 
+
   if (!strcmp(algorithm, "md5"))
-    alg = GNUTLS_DIG_MD5;
+  {
+   /*
+    * Some versions of GNU TLS disable MD5 without warning...
+    */
+
+    _cups_md5_state_t  state;          /* MD5 state info */
+
+    if (hashsize < 16)
+      goto too_small;
+
+    _cupsMD5Init(&state);
+    _cupsMD5Append(&state, data, datalen);
+    _cupsMD5Finish(&state, hash);
+
+    return (16);
+  }
   else if (!strcmp(algorithm, "sha"))
     alg = GNUTLS_DIG_SHA1;
   else if (!strcmp(algorithm, "sha2-224"))
@@ -242,6 +259,9 @@ cupsHashData(const char    *algorithm,      /* I - Algorithm name */
   {
     _cups_md5_state_t  state;          /* MD5 state info */
 
+    if (hashsize < 16)
+      goto too_small;
+
     _cupsMD5Init(&state);
     _cupsMD5Append(&state, data, datalen);
     _cupsMD5Finish(&state, hash);