Răsfoiți Sursa

Fix openssl 1.1 forward compat.

The main problem was the lack of --export-dynamic. The stub symbols
need to be exported (like a shlib) so that dlsym(3) can work on them.
Bryan Drewery 6 ani în urmă
părinte
comite
f4695a01a9
5 a modificat fișierele cu 25 adăugiri și 10 ștergeri
  1. 1 0
      doc/UPDATES.md
  2. 3 1
      src/Makefile.in
  3. 4 0
      src/compat/openssl.cc
  4. 7 7
      src/dl.h
  5. 10 2
      src/generate_defs.sh

+ 1 - 0
doc/UPDATES.md

@@ -8,6 +8,7 @@
   * Fix cmd_slowjoin still adding the channel on parsing error.
   * Fix -Wwritable-strings warnings
   * Fix dirname(3) support on FreeBSD (#89).
+  * Fix OpenSSL 1.1 forward compat.
 
 # 1.4.9
   * Fix various compile warnings and spam

+ 3 - 1
src/Makefile.in

@@ -15,6 +15,7 @@ LDFLAGS = @LDFLAGS@ $(DEBLDFLAGS)
 SETTINGSFILE = $(top_srcdir)/doc/settings.txt
 RESPONSESFILE = $(top_srcdir)/doc/responses.txt
 HELPFILE = $(top_srcdir)/doc/help.txt
+EXPORTS = $(srcdir)/.defs/exports
 
 include $(top_srcdir)/build/build.mk
 
@@ -113,7 +114,8 @@ sorthelp: sorthelp.cc $(top_builddir)/lib/bdlib/src/libbdlib.a
 
 ../$(EGGEXEC): $(OBJS) $(top_builddir)/lib/bdlib/src/libbdlib.a @LIBELF_BUNDLED@
 	@echo -e "[LD ]	\033[1m$@\033[0m"
-	$(LD) $(LDFLAGS) -o ../$(EGGEXEC) $(OBJS) $(top_builddir)/lib/bdlib/src/libbdlib.a $(LIBS) @LIBELF_LIB@
+	$(LD) $(LDFLAGS) -o ../$(EGGEXEC) $(OBJS) $(top_builddir)/lib/bdlib/src/libbdlib.a \
+	    $(LIBS) @LIBELF_LIB@ -Wl,--dynamic-list=$(EXPORTS)
 	@$(STRIP) ../$(EGGEXEC)
 	@$(OBJCOPY) ../$(EGGEXEC)
 	@echo "Successful compile: $(EGGEXEC)"

+ 4 - 0
src/compat/openssl.cc

@@ -1,4 +1,5 @@
 #include <openssl/opensslv.h>
+/* Provide forward compat functions when built from < 1.1. */
 #if !defined(LIBRESSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER < 0x10100000L
 #include <stdlib.h>
 #include <stdint.h>
@@ -13,12 +14,15 @@ int _OPENSSL_init_ssl(uint64_t a1, const void *a2) {
   return DLSYM_VAR(OPENSSL_init_ssl)(a1, a2);
 }
 
+void _ERR_free_strings(void) __attribute__((const));
 void _ERR_free_strings(void) {
 }
 
+void _EVP_cleanup(void) __attribute__((const));
 void _EVP_cleanup(void) {
 }
 
+void _CRYPTO_cleanup_all_ex_data(void) __attribute__((const));
 void _CRYPTO_cleanup_all_ex_data(void) {
 }
 

+ 7 - 7
src/dl.h

@@ -22,14 +22,14 @@ extern const char *dlsym_error;
 #define DLSYM_GLOBAL_FWDCOMPAT(_handle, x) do { \
   dlerror(); \
   if ((dl_symbol_table[#x] = (FunctionPtr) ((x##_t) dlsym(_handle, #x))) == \
-    NULL) { \
-    if ((dl_symbol_table[#x] = \
+    NULL && \
+    dlerror() && \
+    (dl_symbol_table[#x] = \
       (FunctionPtr) ((x##_t) dlsym(NULL, "_" #x))) == NULL) { \
-      dlsym_error = dlerror(); \
-      if (dlsym_error) { \
-        fprintf(stderr, "%s", dlsym_error); \
-        return(1); \
-      } \
+    dlsym_error = dlerror(); \
+    if (dlsym_error) { \
+      fprintf(stderr, "%s", dlsym_error); \
+      return(1); \
     } \
   } else { \
     my_symbols << #x; \

+ 10 - 2
src/generate_defs.sh

@@ -13,6 +13,7 @@ INCLUDES="${TCL_INCLUDES} ${SSL_INCLUDES}"
 mkdir -p src/.defs > /dev/null 2>&1
 TMPFILE=$(mktemp "/tmp/pre.XXXXXX")
 files=$(grep -l DLSYM_GLOBAL src/*.cc|grep -v "src/_")
+exportsFile="src/.defs/exports"
 
 for file in ${files}; do
   suffix=${file##*.}
@@ -29,6 +30,7 @@ for file in ${files}; do
   : > $defsFile_wrappers
 done
 
+echo "{" > $exportsFile
 for file in ${files}; do
   suffix=${file##*.}
   basename=${file%%.*}
@@ -51,7 +53,8 @@ for file in ${files}; do
   mv $TMPFILE.sed $TMPFILE
   cd ..
 
-  for symbol in $($SED -n -e 's/.*DLSYM_GLOBAL[^ (]*(.*, \([^)]*\).*/\1/p' $TMPFILE|sort -u); do
+  $SED -n -e 's/.*\(DLSYM_GLOBAL[^ (]*\)(.*, \([^)]*\).*/\2 \1/p' $TMPFILE | \
+    sort -u | while read symbol dlsym; do
     # Check if the typedef is already defined ...
     typedef=$(grep "^typedef .*(\*${symbol}_t)" ${dirname}/${basename}.h)
     # ... if not, generate it
@@ -70,7 +73,11 @@ for file in ${files}; do
     fi
 
     #pipe typedef into generate_symbol.sh
-    test -n "$typedef" && echo "${symbol} ${existing_typedef} ${typedef}"
+    [ -z "$typedef" ] && continue
+    if [ "${dlsym}" = "DLSYM_GLOBAL_FWDCOMPAT" ]; then
+      echo "_${symbol};" >> $exportsFile
+    fi
+    echo "${symbol} ${existing_typedef} ${typedef}"
   done | src/generate_symbol.sh $defsFile_wrappers $defsFile_pre $defsFile_post
 
   echo "}" >> $defsFile_wrappers
@@ -78,4 +85,5 @@ for file in ${files}; do
 
   echo "done"
 done
+echo "};">> $exportsFile
 rm -f $TMPFILE