1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-06-20 00:15:31 +00:00

bug 1081: Fix regfree crashes by changing order of libraries

This commit is contained in:
Kalle Olavi Niemitalo 2009-06-11 00:47:33 +03:00 committed by Kalle Olavi Niemitalo
parent dedd01c970
commit 4f29067169
2 changed files with 44 additions and 2 deletions

7
NEWS
View File

@ -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:
----------------

View File

@ -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 <tre/regex.h>],
[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 <tre/regex.h> 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 <regex.h> 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 <tre/regex.h> 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=