]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Fix 64-bit compile issues in rev.13785
authorAmos Jeffries <squid3@treenet.co.nz>
Tue, 30 Dec 2014 13:40:33 +0000 (05:40 -0800)
committerAmos Jeffries <squid3@treenet.co.nz>
Tue, 30 Dec 2014 13:40:33 +0000 (05:40 -0800)
The Nettle 3.0 library API imported and used by rev.13785 defines
function symbols with size_t parameters where earlier libraries used
'unsigned'. This matters on 64-bit systems where unsigned is a 'int'
and size_t a 'long' - implicit conversion is not possible.

Explicitly detect the size_t API existence during ./configure time and
use the built-in logics if supplied Nettle library is an older version.

configure.ac
include/base64.h
lib/base64.c

index 50660c6a8343a8f480f3c9727722e109c7ba6c67..5aa63fdc019c2333fb790def73b5232aa6595257 100644 (file)
@@ -1199,8 +1199,32 @@ case "$with_nettle" in
 if test "x$with_nettle" != "xno" ; then
   AC_CHECK_LIB(nettle, nettle_md5_init,[
     NETTLELIB="$NETTLELIBDIR -lnettle"
-    AC_CHECK_HEADERS(nettle/md5.h nettle/base64.h)
+    AC_CHECK_HEADERS(nettle/md5.h)
   ],[with_nettle=no])
+  if test "x$with_nettle" != "xno" ; then
+    # Base64 uses the nettle 3.0 API
+    # which matters on 64-bit systems
+    AC_CHECK_HEADERS(nettle/base64.h)
+    AC_MSG_CHECKING([for Nettle 3.0 API compatibility])
+    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+#     include <cstddef>
+#     include <cstdint>
+#     include <nettle/base64.h>
+    ]],[[
+      uint8_t inData[10]; inData[0] = '\0';
+      size_t srcLen = 0;
+      struct base64_decode_ctx ctx;
+      base64_decode_init(&ctx);
+      uint8_t outData[10];
+      size_t dstLen = 0;
+      if (!base64_decode_update(&ctx, &dstLen, outData, srcLen, inData) ||
+              !base64_decode_final(&ctx)) {
+          return 1;
+      }
+    ]])],[AC_MSG_RESULT(yes)
+      AC_DEFINE(HAVE_NETTLE30_BASE64,1,[set to 1 if Nettle 3.0 API will link])
+    ],[AC_MSG_RESULT(no)])
+  fi
 fi
 AC_MSG_NOTICE([Using Nettle cryptographic library: ${with_nettle:=yes}])
 AC_SUBST(NETTLELIB)
index 35cc7ef710b019b85e1bb21c29ae13d0b85f6c26..fdf09d3ce46ebec9ab596ef2bddc50d628a268a5 100644 (file)
@@ -9,7 +9,7 @@
 #ifndef _SQUID_BASE64_H
 #define _SQUID_BASE64_H
 
-#if HAVE_NETTLE_BASE64_H
+#if HAVE_NETTLE_BASE64_H && HAVE_NETTLE30_BASE64
 #include <nettle/base64.h>
 
 #else /* Base64 functions copied from Nettle 3.0 under GPLv2, with adjustments */
index 3926045fe256e7752c12808db080282df0aecb1d..49154949421c1c381343cdba32a17f53872e66e0 100644 (file)
@@ -13,7 +13,7 @@
 #include "squid.h"
 #include "base64.h"
 
-#if !HAVE_NETTLE_BASE64_H
+#if !HAVE_NETTLE_BASE64_H || !HAVE_NETTLE30_BASE64
 
 #if HAVE_STDLIB_H
 #include <stdlib.h>
@@ -268,5 +268,5 @@ base64_encode_final(struct base64_encode_ctx *ctx,
     return done;
 }
 
-#endif /* HAVE_NETTLE_BASE64_H */
+#endif /* !HAVE_NETTLE_BASE64_H || !HAVE_NETTLE30_BASE64 */