From 4f29067169c5db19559ee400174172f48b428009 Mon Sep 17 00:00:00 2001 From: Kalle Olavi Niemitalo Date: Thu, 11 Jun 2009 00:47:33 +0300 Subject: [PATCH] bug 1081: Fix regfree crashes by changing order of libraries --- NEWS | 7 +++++++ configure.in | 39 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index a84f3f9c..595191b9 100644 --- a/NEWS +++ b/NEWS @@ -16,6 +16,13 @@ includes the changes listed under ``ELinks 0.11.6.GIT now'' below. protocol.http.compression by default, until ELinks can report decompression errors or automatically retry the connection. +Bugs that should be removed from NEWS before the 0.12.0 release: + +* critical bug 1081: To fix crashes caused by different definitions of + regfree() in TRE and in the system libc, link with TRE before any + other libraries. ELinks 0.12pre4 was the first release that had + this bug. + ELinks 0.12pre4: ---------------- diff --git a/configure.in b/configure.in index 445abcf7..4380de0d 100644 --- a/configure.in +++ b/configure.in @@ -958,7 +958,7 @@ else AC_MSG_CHECKING([[for TRE header and library]]) EL_SAVE_FLAGS CFLAGS="$TRE_CFLAGS $CFLAGS" - LIBS="$TRE_LIBS $LIBS" + LIBS="$TRE_LIBS $LIBS" # must be first, because of regfree conflict AC_TRY_LINK([#include ], [regex_t re; regmatch_t match[1]; @@ -1398,6 +1398,9 @@ AC_ARG_ENABLE(weehoofooboomookerchoo, # This must be done after the CONFIG_UTF8 check above. # The first part of the TRE check is separate, to get # the configure --help output in a sensible order. +# +# After this section, nothing else must be added to the +# beginning of $LIBS. if test "$tre_log" = "available"; then if test "$CONFIG_UTF8" = "yes"; then @@ -1441,7 +1444,39 @@ if test "$tre_log" = "TRE"; then AC_DEFINE([CONFIG_TRE], [1], [Define as 1 to use the TRE library for regular expression searching. This requires the header file. If you define CONFIG_UTF8 too, then wchar_t must be exactly 32-bit so that it matches unicode_val_T.]) # TRE_CFLAGS will be used only where needed. - LIBS="$LIBS $TRE_LIBS" + # + # Bug 1081: If both TRE and libc define the regfree function, + # ELinks needs to use the version defined by TRE because + # that's the one compatible with regex_t initialized by the + # regwcomp function of TRE. Therefore put $TRE_LIBS at the + # very beginning of $LIBS so that the linker hopefully finds + # regfree there before it examines libc. In particular, + # $PERL_LIBS appears to often include "-lc". + # + # This scheme still risks a crash if ELinks is linked with + # some static library that uses GNU extensions that + # TRE does not implement. For example, the library might call + # re_compile_pattern, which is found in GNU libc, and then + # regfree, which is found in TRE and probably crashes with the + # GNU-initialized regex_t. Ways to avoid such crashes: + # + # - Change TRE so it defines only tre_... functions and does + # not attempt to override the POSIX names by default. + # + # - Change ELinks to access TRE only via dlopen and dlsym. + # The problem then is how to find the correct file name. + # There might be libtre.so.4 and libtre.so.5 with different + # ABI. How can this configure script detect which of them + # matches the in the include path? + # + # - Replace the static library with a shared library. At + # least on GNU/Linux, when the shared library is built, the + # linker should note that e.g. regfree is defined in libc + # and has the GLIBC_2.0 version there, and write that + # version string to the shared library as well; because TRE + # does not provide regfree with that version, any regfree + # calls at run time should then get resolved to libc. + LIBS="$TRE_LIBS $LIBS" else TRE_LIBS= TRE_CFLAGS=