diff --git a/ChangeLog b/ChangeLog index da494b12..b5dbe69f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +1999-01-09 Thomas Tanner + + * NEWS: support for BSD/OS 4.x was not documented + * demo/Makefile.am: link against libm only if available + * mdemo/Makefile.am: likewise, use -avoid-versioning flag + instead of -avoid-version (typo) + * demo/configure.in: check for libm, string.h and math.h + * mdemo/configure.in: likewise + * depdemo/configure.in: check for libm and math.h + * libltdl/ltdl.c: check for buffer overflows + 1999-01-07 Gary V. Vaughan * ltmain.sh (cygwin, allow_undefined): Unfortunately, there are diff --git a/NEWS b/NEWS index 1bfc362e..bac6df3a 100644 --- a/NEWS +++ b/NEWS @@ -2,7 +2,7 @@ NEWS - list of user-visible changes between releases of GNU Libtool New in 1.2e: CVS version: * Support for BeOS -* Improved support for Win32, SysV 4.3 and NetBSD +* Improved support for Win32, SysV 4.3, BSD/OS 4.x and NetBSD * Various bugfixes New in 1.2c: CVS version; 1.2d: 1998-12-16, Libtool team: diff --git a/demo/Makefile.am b/demo/Makefile.am index ceb1519e..9034bc46 100644 --- a/demo/Makefile.am +++ b/demo/Makefile.am @@ -10,7 +10,7 @@ CLEANFILES = $(hardcode_tests) # Build a libtool library, libhello.la for installation in libdir. lib_LTLIBRARIES = libhello.la libhello_la_SOURCES = hello.c foo.c -libhello_la_LDFLAGS = -version-info 3:12:1 -lm +libhello_la_LDFLAGS = -version-info 3:12:1 $(LIBADD_M) include_HEADERS = foo.h diff --git a/demo/configure.in b/demo/configure.in index 2018f4e8..97511c2e 100644 --- a/demo/configure.in +++ b/demo/configure.in @@ -9,5 +9,10 @@ AM_PROG_LIBTOOL AM_CONDITIONAL(BINARY_HELLDL, [dnl grep '^global_symbol_pipe=..*$' ./libtool >/dev/null]) +AC_CHECK_HEADERS(string.h math.h) + +AC_CHECK_LIB(m, cos, LIBADD_M="-lm", LIBADD_M=) +AC_SUBST(LIBADD_M) + dnl Output the makefile AC_OUTPUT(Makefile) diff --git a/demo/dlmain.c b/demo/dlmain.c index 6a26c596..aa0095d6 100644 --- a/demo/dlmain.c +++ b/demo/dlmain.c @@ -19,7 +19,10 @@ USA. */ #include "foo.h" #include + +#ifdef HAVE_STRING_H #include +#endif struct dld_symlist { diff --git a/demo/foo.c b/demo/foo.c index 19b6e9b3..d0661166 100644 --- a/demo/foo.c +++ b/demo/foo.c @@ -23,7 +23,10 @@ USA. */ #undef _LIBFOO_COMPILATION #include + +#ifdef HAVE_MATH_H #include +#endif /* Give a global variable definition. */ int nothing = FOO_RET; diff --git a/depdemo/Makefile.am b/depdemo/Makefile.am index 21433092..b4dfece3 100644 --- a/depdemo/Makefile.am +++ b/depdemo/Makefile.am @@ -9,7 +9,7 @@ libl2_la_LIBADD = libl1.la libl3_la_SOURCES = l3.c l3.h sysdep.h libl3_la_LIBADD = libl1.la libl2.la libl4_la_SOURCES = l4.c l4.h sysdep.h -libl4_la_LIBADD = libl3.la -lm +libl4_la_LIBADD = libl3.la $(LIBADD_M) bin_PROGRAMS = depdemo depdemo.static diff --git a/depdemo/configure.in b/depdemo/configure.in index f1120a2a..5a19db94 100644 --- a/depdemo/configure.in +++ b/depdemo/configure.in @@ -6,7 +6,10 @@ AC_PROG_CC AC_EXEEXT AM_PROG_LIBTOOL -AC_CHECK_HEADERS(string.h) +AC_CHECK_HEADERS(math.h) + +AC_CHECK_LIB(m, cos, LIBADD_M="-lm", LIBADD_M=) +AC_SUBST(LIBADD_M) dnl Output the makefile AC_OUTPUT(Makefile) diff --git a/depdemo/l4.c b/depdemo/l4.c index 8a975fe7..94019b93 100644 --- a/depdemo/l4.c +++ b/depdemo/l4.c @@ -21,7 +21,10 @@ USA. */ #include "l3.h" #include + +#ifdef HAVE_MATH_H #include +#endif int var_l4; diff --git a/libltdl/ltdl.c b/libltdl/ltdl.c index 72736da5..516bd50f 100644 --- a/libltdl/ltdl.c +++ b/libltdl/ltdl.c @@ -628,7 +628,7 @@ tryall_dlopen (handle, filename) } #undef MAX_FILENAME -#define MAX_FILENAME 1024 +#define MAX_FILENAME 2048 static int find_module (handle, dir, libdir, dlname, old_name) @@ -638,26 +638,32 @@ find_module (handle, dir, libdir, dlname, old_name) const char *dlname; const char *old_name; { - char fullname[MAX_FILENAME]; /* FIXME: unchecked buffer */ + char fullname[MAX_FILENAME]; /* search a module */ if (*dlname) { /* try to open the installed module */ - strcpy(fullname, libdir); - strcat(fullname, "/"); - strcat(fullname, dlname); - if (tryall_dlopen(handle, fullname) == 0) - return 0; + if (strlen(libdir)+strlen(dlname)+1 < MAX_FILENAME) { + strcpy(fullname, libdir); + strcat(fullname, "/"); + strcat(fullname, dlname); + if (tryall_dlopen(handle, fullname) == 0) + return 0; + } /* try to open the not-installed module */ - strcpy(fullname, dir); - strcat(fullname, ".libs/"); - strcat(fullname, dlname); - if (tryall_dlopen(handle, fullname) == 0) - return 0; - strcpy(fullname, dir); - strcat(fullname, dlname); - if (tryall_dlopen(handle, fullname) == 0) - return 0; + if (strlen(dir)+strlen(dlname)+6 < MAX_FILENAME) { + strcpy(fullname, dir); + strcat(fullname, ".libs/"); + strcat(fullname, dlname); + if (tryall_dlopen(handle, fullname) == 0) + return 0; + } + if (strlen(dir)+strlen(dlname) < MAX_FILENAME) { + strcpy(fullname, dir); + strcat(fullname, dlname); + if (tryall_dlopen(handle, fullname) == 0) + return 0; + } } if (*old_name && tryall_dlopen(handle, old_name) == 0) return 0; @@ -678,25 +684,23 @@ lt_dlopen (filename) { lt_dlhandle handle; FILE *file; - char dir[MAX_FILENAME]; /* FIXME: unchecked buffer */ - char tmp[MAX_FILENAME]; /* FIXME: unchecked buffer */ + char dir[MAX_FILENAME]; + char tmp[MAX_FILENAME]; const char *basename, *ext, *search_path; - handle = (lt_dlhandle) malloc(sizeof(lt_dlhandle_t)); - if (!handle) - return 0; basename = strrchr(filename, '/'); if (basename) basename++; else basename = filename; + if (basename - filename >= MAX_FILENAME) + return 0; strncpy(dir, filename, basename - filename); dir[basename - filename] = '\0'; search_path = getenv("LTDL_LIBRARY_PATH"); /* get the search path */ /* check whether we open a libtool module (.la extension) */ ext = strrchr(basename, '.'); if (ext && strcmp(ext, ".la") == 0) { - /* FIXME: unchecked buffers */ char dlname[MAX_FILENAME], old_name[MAX_FILENAME]; char libdir[MAX_FILENAME], preload[MAX_FILENAME]; int i; @@ -708,29 +712,35 @@ lt_dlopen (filename) /* try other directories */ const char *p, *next; + /* search_path is a colon-separated + list of search directories */ p = search_path; while (!file && p) { next = strchr(p, ':'); if (next) { + if (next - p + 1 >= MAX_FILENAME) + return 0; strncpy(dir, p, next - p); dir[next - p] = '\0'; p = next+1; } else { + if (strlen(p)+1 >= MAX_FILENAME) + return 0; strcpy(dir, p); p = 0; } if (!*dir) continue; strcat(dir, "/"); - strcpy(tmp, dir); - strcat(tmp, basename); - file = fopen(tmp, READTEXT_MODE); + if (strlen(dir)+strlen(basename) < MAX_FILENAME) { + strcpy(tmp, dir); + strcat(tmp, basename); + file = fopen(tmp, READTEXT_MODE); + } } } - if (!file) { - free(handle); + if (!file) return 0; - } while (!feof(file)) { if (!fgets(tmp, MAX_FILENAME, file)) break; @@ -747,13 +757,18 @@ lt_dlopen (filename) trim(preload, &tmp[13]); } fclose(file); - /* TODO: preload required libraries */ + /* FIXME: preload required libraries */ + handle = (lt_dlhandle) malloc(sizeof(lt_dlhandle_t)); + if (!handle) + return 0; if (find_module(&handle, dir, libdir, dlname, old_name)) { free(handle); return 0; } /* extract the module name from the file name */ + if (basename >= MAX_FILENAME) + return 0; strcpy(tmp, basename); tmp[ext - basename] = '\0'; /* canonicalize the modul name */ @@ -763,6 +778,10 @@ lt_dlopen (filename) handle->name = strdup(tmp); } else { /* not a libtool module */ + handle = (lt_dlhandle) malloc(sizeof(lt_dlhandle_t)); + if (!handle) + return 0; + if (tryall_dlopen(*handle, filename)) { int error = 1; @@ -770,23 +789,31 @@ lt_dlopen (filename) /* try other directories */ const char *p, *next; - p = search_path; + /* search_path is a colon-separated + list of search directories */ + p = search_path; while (error && p) { next = strchr(p, ':'); if (next) { + if (next - p + 1 >= MAX_FILENAME) + return 0; strncpy(dir, p, next - p); dir[next - p] = '\0'; p = next+1; } else { + if (strlen(p)+1 >= MAX_FILENAME) + return 0; strcpy(dir, p); p = 0; } if (!*dir) continue; strcat(dir, "/"); - strcpy(tmp, dir); - strcat(tmp, basename); - error = tryall_dlopen(*handle, tmp); + if (strlen(dir)+strlen(basename) < MAX_FILENAME) { + strcpy(tmp, dir); + strcat(tmp, basename); + error = tryall_dlopen(*handle, tmp); + } } } if (error) { @@ -834,33 +861,42 @@ lt_dlclose (handle) return 0; } +#define MAX_SYMBOL_LENGTH 128 + lt_ptr_t lt_dlsym (handle, symbol) lt_dlhandle handle; const char *symbol; { - char sym[128]; /* FIXME: unchecked buffer */ + char sym[MAX_SYMBOL_LENGTH]; lt_ptr_t address; - if (handle->name) { /* this is a libtool module */ #ifdef NEED_USCORE + if (handle->name && strlen(handle->name) < MAX_SYMBOL_LENGTH-6) { + /* this is a libtool module */ /* prefix symbol with leading underscore */ strcpy(sym, "_"); strcat(sym, handle->name); #else + if (handle->name && strlen(handle->name) < MAX_SYMBOL_LENGTH-5) { + /* this is a libtool module */ strcpy(sym, handle->name); #endif strcat(sym, "_LTX_"); - strcat(sym, symbol); - /* try "modulename_LTX_symbol" */ - address = handle->type->find_sym(handle, sym); - if (address) - return address; + if (strlen(sym)+strlen(symbol) < MAX_SYMBOL_LENGTH) { + strcat(sym, symbol); + /* try "modulename_LTX_symbol" */ + address = handle->type->find_sym(handle, sym); + if (address) + return address; + } } /* otherwise try "symbol" */ #ifdef NEED_USCORE /* prefix symbol with leading underscore */ strcpy(sym, "_"); + if (strlen(symbol) >= MAX_SYMBOL_LENGTH) + return 0; strcat(sym, symbol); return handle->type->find_sym(handle, sym); #else diff --git a/mdemo/Makefile.am b/mdemo/Makefile.am index e7052884..5c8a6331 100644 --- a/mdemo/Makefile.am +++ b/mdemo/Makefile.am @@ -9,10 +9,10 @@ EXTRA_DIST = acinclude.m4 lib_LTLIBRARIES = libfoo1.la libfoo2.la libfoo1_la_SOURCES = foo1.c -libfoo1_la_LDFLAGS = -lm -module -avoid-version +libfoo1_la_LDFLAGS = $(LIBADD_M) -module -avoid-versioning libfoo2_la_SOURCES = foo2.c -libfoo2_la_LDFLAGS = -lm -module +libfoo2_la_LDFLAGS = $(LIBADD_M) -module noinst_HEADERS = foo.h @@ -21,7 +21,7 @@ bin_PROGRAMS = mdemo mdemo.debug # Create a version of mdemo that does dlopen. mdemo_SOURCES = main.c mdemo_LDADD = ../libltdl/libltdl.la \ - -lm # We won't need this when libltdl takes care of dependencies + $(LIBADD_M) # We won't need this when libltdl takes care of dependencies mdemo_LDFLAGS = -export-dynamic -dlopen libfoo1.la -dlopen libfoo2.la mdemo_DEPENDENCIES = ../libltdl/libltdl.la libfoo1.la libfoo2.la diff --git a/mdemo/configure.in b/mdemo/configure.in index 284a7c8f..374156e8 100644 --- a/mdemo/configure.in +++ b/mdemo/configure.in @@ -6,5 +6,10 @@ AC_PROG_CC AC_EXEEXT AM_PROG_LIBTOOL +AC_CHECK_HEADERS(string.h math.h) + +AC_CHECK_LIB(m, cos, LIBADD_M="-lm", LIBADD_M=) +AC_SUBST(LIBADD_M) + dnl Output the makefile AC_OUTPUT(Makefile) diff --git a/mdemo/foo1.c b/mdemo/foo1.c index edc7321d..d98c554b 100644 --- a/mdemo/foo1.c +++ b/mdemo/foo1.c @@ -20,7 +20,10 @@ USA. */ #include "foo.h" #include + +#ifdef HAVE_MATH_H #include +#endif #define nothing libfoo1_LTX_nothing #define foo1 libfoo1_LTX_foo1 diff --git a/mdemo/foo2.c b/mdemo/foo2.c index 588c3b8f..4c8ddcc0 100644 --- a/mdemo/foo2.c +++ b/mdemo/foo2.c @@ -20,7 +20,10 @@ USA. */ #include "foo.h" #include + +#ifdef HAVE_MATH_H #include +#endif #define nothing libfoo2_LTX_nothing #define foo2 libfoo2_LTX_foo2 diff --git a/mdemo/main.c b/mdemo/main.c index 4f8e032f..f72dcf0c 100644 --- a/mdemo/main.c +++ b/mdemo/main.c @@ -21,8 +21,14 @@ USA. */ #include "foo.h" #include "ltdl.h" #include + +#ifdef HAVE_STRING_H #include +#endif + +#ifdef HAVE_MATH_H #include +#endif /* import sin and cos (used by the modules) */ extern double sin (double x);