2017-12-10 22:00:49 +00:00
|
|
|
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
|
2017-12-04 19:24:00 +00:00
|
|
|
From: Fedora GDB patches <invalid@email.com>
|
|
|
|
Date: Fri, 27 Oct 2017 21:07:50 +0200
|
|
|
|
Subject: gdb-rhbz1156192-recursive-dlopen-test.patch
|
|
|
|
|
2017-12-08 04:31:26 +00:00
|
|
|
;; Testcase for '[SAP] Recursive dlopen causes SAP HANA installer to
|
|
|
|
;; crash.' (RH BZ 1156192).
|
|
|
|
;;=fedoratest
|
|
|
|
|
|
|
|
diff --git a/gdb/testsuite/gdb.base/gdb-rhbz1156192-recursive-dlopen-libbar.c b/gdb/testsuite/gdb.base/gdb-rhbz1156192-recursive-dlopen-libbar.c
|
|
|
|
new file mode 100644
|
|
|
|
--- /dev/null
|
|
|
|
+++ b/gdb/testsuite/gdb.base/gdb-rhbz1156192-recursive-dlopen-libbar.c
|
2016-10-20 20:30:43 +00:00
|
|
|
@@ -0,0 +1,30 @@
|
|
|
|
+/* Testcase for recursive dlopen calls.
|
|
|
|
+
|
|
|
|
+ Copyright (C) 2014 Free Software Foundation, Inc.
|
|
|
|
+
|
|
|
|
+ This file is part of GDB.
|
|
|
|
+
|
|
|
|
+ This program is free software; you can redistribute it and/or modify
|
|
|
|
+ it under the terms of the GNU General Public License as published by
|
|
|
|
+ the Free Software Foundation; either version 3 of the License, or
|
|
|
|
+ (at your option) any later version.
|
|
|
|
+
|
|
|
|
+ This program is distributed in the hope that it will be useful,
|
|
|
|
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
+ GNU General Public License for more details.
|
|
|
|
+
|
|
|
|
+ You should have received a copy of the GNU General Public License
|
|
|
|
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
|
+
|
|
|
|
+/* This test was copied from glibc's testcase called
|
|
|
|
+ <dlfcn/tst-rec-dlopen.c> and related files. */
|
|
|
|
+
|
|
|
|
+#include <stdio.h>
|
|
|
|
+#include <stdlib.h>
|
|
|
|
+
|
|
|
|
+void
|
|
|
|
+bar (void)
|
|
|
|
+{
|
|
|
|
+ printf ("Called bar.\n");
|
|
|
|
+}
|
2017-12-08 04:31:26 +00:00
|
|
|
diff --git a/gdb/testsuite/gdb.base/gdb-rhbz1156192-recursive-dlopen-libfoo.c b/gdb/testsuite/gdb.base/gdb-rhbz1156192-recursive-dlopen-libfoo.c
|
|
|
|
new file mode 100644
|
|
|
|
--- /dev/null
|
|
|
|
+++ b/gdb/testsuite/gdb.base/gdb-rhbz1156192-recursive-dlopen-libfoo.c
|
2016-10-20 20:30:43 +00:00
|
|
|
@@ -0,0 +1,30 @@
|
|
|
|
+/* Testcase for recursive dlopen calls.
|
|
|
|
+
|
|
|
|
+ Copyright (C) 2014 Free Software Foundation, Inc.
|
|
|
|
+
|
|
|
|
+ This file is part of GDB.
|
|
|
|
+
|
|
|
|
+ This program is free software; you can redistribute it and/or modify
|
|
|
|
+ it under the terms of the GNU General Public License as published by
|
|
|
|
+ the Free Software Foundation; either version 3 of the License, or
|
|
|
|
+ (at your option) any later version.
|
|
|
|
+
|
|
|
|
+ This program is distributed in the hope that it will be useful,
|
|
|
|
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
+ GNU General Public License for more details.
|
|
|
|
+
|
|
|
|
+ You should have received a copy of the GNU General Public License
|
|
|
|
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
|
+
|
|
|
|
+/* This test was copied from glibc's testcase called
|
|
|
|
+ <dlfcn/tst-rec-dlopen.c> and related files. */
|
|
|
|
+
|
|
|
|
+#include <stdio.h>
|
|
|
|
+#include <stdlib.h>
|
|
|
|
+
|
|
|
|
+void
|
|
|
|
+foo (void)
|
|
|
|
+{
|
|
|
|
+ printf ("Called foo.\n");
|
|
|
|
+}
|
2017-12-08 04:31:26 +00:00
|
|
|
diff --git a/gdb/testsuite/gdb.base/gdb-rhbz1156192-recursive-dlopen.c b/gdb/testsuite/gdb.base/gdb-rhbz1156192-recursive-dlopen.c
|
|
|
|
new file mode 100644
|
|
|
|
--- /dev/null
|
|
|
|
+++ b/gdb/testsuite/gdb.base/gdb-rhbz1156192-recursive-dlopen.c
|
2021-03-26 18:40:18 +00:00
|
|
|
@@ -0,0 +1,125 @@
|
2016-10-20 20:30:43 +00:00
|
|
|
+/* Testcase for recursive dlopen calls.
|
|
|
|
+
|
|
|
|
+ Copyright (C) 2014 Free Software Foundation, Inc.
|
|
|
|
+
|
|
|
|
+ This file is part of GDB.
|
|
|
|
+
|
|
|
|
+ This program is free software; you can redistribute it and/or modify
|
|
|
|
+ it under the terms of the GNU General Public License as published by
|
|
|
|
+ the Free Software Foundation; either version 3 of the License, or
|
|
|
|
+ (at your option) any later version.
|
|
|
|
+
|
|
|
|
+ This program is distributed in the hope that it will be useful,
|
|
|
|
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
+ GNU General Public License for more details.
|
|
|
|
+
|
|
|
|
+ You should have received a copy of the GNU General Public License
|
|
|
|
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
|
+
|
|
|
|
+/* This test was copied from glibc's testcase called
|
|
|
|
+ <dlfcn/tst-rec-dlopen.c> and related files. */
|
|
|
|
+
|
|
|
|
+#include <stdio.h>
|
|
|
|
+#include <stdlib.h>
|
|
|
|
+#include <malloc.h>
|
|
|
|
+#include <dlfcn.h>
|
|
|
|
+
|
|
|
|
+#define DSO "gdb-rhbz1156192-recursive-dlopen-libfoo.so"
|
|
|
|
+#define FUNC "foo"
|
|
|
|
+
|
|
|
|
+#define DSO1 "gdb-rhbz1156192-recursive-dlopen-libbar.so"
|
|
|
|
+#define FUNC1 "bar"
|
|
|
|
+
|
|
|
|
+/* Prototype for my hook. */
|
|
|
|
+void *custom_malloc_hook (size_t, const void *);
|
|
|
|
+
|
|
|
|
+/* Pointer to old malloc hooks. */
|
|
|
|
+void *(*old_malloc_hook) (size_t, const void *);
|
|
|
|
+
|
|
|
|
+/* Call function func_name in DSO dso_name via dlopen. */
|
|
|
|
+void
|
|
|
|
+call_func (const char *dso_name, const char *func_name)
|
|
|
|
+{
|
|
|
|
+ int ret;
|
|
|
|
+ void *dso;
|
|
|
|
+ void (*func) (void);
|
|
|
|
+ char *err;
|
|
|
|
+
|
|
|
|
+ /* Open the DSO. */
|
|
|
|
+ dso = dlopen (dso_name, RTLD_NOW|RTLD_GLOBAL);
|
|
|
|
+ if (dso == NULL)
|
|
|
|
+ {
|
|
|
|
+ err = dlerror ();
|
|
|
|
+ fprintf (stderr, "%s\n", err);
|
|
|
|
+ exit (1);
|
|
|
|
+ }
|
|
|
|
+ /* Clear any errors. */
|
|
|
|
+ dlerror ();
|
|
|
|
+
|
|
|
|
+ /* Lookup func. */
|
|
|
|
+ *(void **) (&func) = dlsym (dso, func_name);
|
|
|
|
+ if (func == NULL)
|
|
|
|
+ {
|
|
|
|
+ err = dlerror ();
|
|
|
|
+ if (err != NULL)
|
|
|
|
+ {
|
|
|
|
+ fprintf (stderr, "%s\n", err);
|
|
|
|
+ exit (1);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ /* Call func twice. */
|
|
|
|
+ (*func) ();
|
|
|
|
+
|
|
|
|
+ /* Close the library and look for errors too. */
|
|
|
|
+ ret = dlclose (dso);
|
|
|
|
+ if (ret != 0)
|
|
|
|
+ {
|
|
|
|
+ err = dlerror ();
|
|
|
|
+ fprintf (stderr, "%s\n", err);
|
|
|
|
+ exit (1);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/* Empty hook that does nothing. */
|
|
|
|
+void *
|
|
|
|
+custom_malloc_hook (size_t size, const void *caller)
|
|
|
|
+{
|
|
|
|
+ void *result;
|
|
|
|
+ /* Restore old hooks. */
|
|
|
|
+ __malloc_hook = old_malloc_hook;
|
|
|
|
+ /* First call a function in another library via dlopen. */
|
|
|
|
+ call_func (DSO1, FUNC1);
|
|
|
|
+ /* Called recursively. */
|
|
|
|
+ result = malloc (size);
|
|
|
|
+ /* Restore new hooks. */
|
2021-03-26 18:40:18 +00:00
|
|
|
+ old_malloc_hook = __malloc_hook;
|
2016-10-20 20:30:43 +00:00
|
|
|
+ __malloc_hook = custom_malloc_hook;
|
|
|
|
+ return result;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+int
|
|
|
|
+main (void)
|
|
|
|
+{
|
|
|
|
+
|
|
|
|
+ /* Save old hook. */
|
|
|
|
+ old_malloc_hook = __malloc_hook;
|
|
|
|
+ /* Install new hook. */
|
|
|
|
+ __malloc_hook = custom_malloc_hook;
|
|
|
|
+
|
|
|
|
+ /* Attempt to dlopen a shared library. This dlopen will
|
|
|
|
+ trigger an access to the ld.so.cache, and that in turn
|
|
|
|
+ will require a malloc to duplicate data in the cache.
|
|
|
|
+ The malloc will call our malloc hook which calls dlopen
|
|
|
|
+ recursively, and upon return of this dlopen the non-ref
|
|
|
|
+ counted ld.so.cache mapping will be unmapped. We will
|
|
|
|
+ return to the original dlopen and crash trying to access
|
|
|
|
+ dlopened data. */
|
|
|
|
+ call_func (DSO, FUNC);
|
|
|
|
+
|
|
|
|
+ /* Restore old hook. */
|
|
|
|
+ __malloc_hook = old_malloc_hook;
|
|
|
|
+
|
|
|
|
+ return 0;
|
|
|
|
+}
|
2017-12-08 04:31:26 +00:00
|
|
|
diff --git a/gdb/testsuite/gdb.base/gdb-rhbz1156192-recursive-dlopen.exp b/gdb/testsuite/gdb.base/gdb-rhbz1156192-recursive-dlopen.exp
|
|
|
|
new file mode 100644
|
|
|
|
--- /dev/null
|
|
|
|
+++ b/gdb/testsuite/gdb.base/gdb-rhbz1156192-recursive-dlopen.exp
|
2021-03-26 18:40:18 +00:00
|
|
|
@@ -0,0 +1,157 @@
|
2016-10-20 20:30:43 +00:00
|
|
|
+# Copyright 2014 Free Software Foundation, Inc.
|
|
|
|
+#
|
|
|
|
+# This program is free software; you can redistribute it and/or modify
|
|
|
|
+# it under the terms of the GNU General Public License as published by
|
|
|
|
+# the Free Software Foundation; either version 3 of the License, or
|
|
|
|
+# (at your option) any later version.
|
|
|
|
+#
|
|
|
|
+# This program is distributed in the hope that it will be useful,
|
|
|
|
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
+# GNU General Public License for more details.
|
|
|
|
+#
|
|
|
|
+# You should have received a copy of the GNU General Public License
|
|
|
|
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
+
|
2021-03-26 18:40:18 +00:00
|
|
|
+if {[skip_shlib_tests]} {
|
|
|
|
+ untested "skipping shlib tests"
|
|
|
|
+ return 0
|
|
|
|
+} elseif {[use_gdb_stub]} {
|
|
|
|
+ untested "skipping tests because of stub"
|
|
|
|
+ return 0
|
2016-10-20 20:30:43 +00:00
|
|
|
+}
|
|
|
|
+
|
|
|
|
+# Library foo
|
|
|
|
+set libname1 "gdb-rhbz1156192-recursive-dlopen-libfoo"
|
|
|
|
+set srcfile_lib1 ${srcdir}/${subdir}/${libname1}.c
|
|
|
|
+set binfile_lib1 [standard_output_file ${libname1}.so]
|
|
|
|
+# Library bar
|
|
|
|
+set libname2 "gdb-rhbz1156192-recursive-dlopen-libbar"
|
|
|
|
+set srcfile_lib2 ${srcdir}/${subdir}/${libname2}.c
|
|
|
|
+set binfile_lib2 [standard_output_file ${libname2}.so]
|
|
|
|
+
|
|
|
|
+set testfile "gdb-rhbz1156192-recursive-dlopen"
|
2016-10-23 20:09:55 +00:00
|
|
|
+set srcfile ${testfile}.c
|
2016-10-20 20:30:43 +00:00
|
|
|
+set executable ${testfile}
|
|
|
|
+set binfile [standard_output_file ${executable}]
|
|
|
|
+
|
|
|
|
+if { [gdb_compile_shlib ${srcfile_lib1} ${binfile_lib1} \
|
|
|
|
+ { debug "additional_flags=-fPIC" }] != "" } {
|
|
|
|
+ untested "Could not compile ${binfile_lib1}"
|
|
|
|
+ return -1
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+if { [gdb_compile_shlib ${srcfile_lib2} ${binfile_lib2} \
|
|
|
|
+ { debug "additional_flags=-fPIC" }] != "" } {
|
|
|
|
+ untested "Could not compile ${binfile_lib2}"
|
|
|
|
+ return -1
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+if { [prepare_for_testing ${testfile}.exp ${executable} ${srcfile} \
|
2016-10-24 21:23:00 +00:00
|
|
|
+ [ list debug shlib_load "additional_flags=-Wno-deprecated-declarations" ]] } {
|
2016-10-20 20:30:43 +00:00
|
|
|
+ untested "Could not compile ${executable}"
|
|
|
|
+ return -1
|
|
|
|
+}
|
|
|
|
+
|
2021-03-26 18:40:18 +00:00
|
|
|
+set supported 0
|
|
|
|
+gdb_test_multiple "run" "initial trial run" {
|
|
|
|
+ -re -wrap "exited normally.*" {
|
|
|
|
+ set supported 1
|
|
|
|
+ pass $gdb_test_name
|
|
|
|
+ }
|
|
|
|
+ -re -wrap "exited with code.*" {
|
|
|
|
+ untested "failed at $gdb_test_name"
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+if { $supported == 0 } {
|
|
|
|
+ return -1
|
|
|
|
+}
|
|
|
|
+
|
2016-10-24 21:23:00 +00:00
|
|
|
+proc do_test { has_libfoo has_libbar } {
|
2016-10-20 20:30:43 +00:00
|
|
|
+ global hex binfile_lib2 binfile_lib1 gdb_prompt
|
|
|
|
+ set libbar_match "[string_to_regexp $binfile_lib2]"
|
|
|
|
+ set libfoo_match "[string_to_regexp $binfile_lib1]"
|
|
|
|
+
|
2016-10-24 21:23:00 +00:00
|
|
|
+ gdb_test_multiple "info shared" "info shared" {
|
|
|
|
+ -re ".*$libfoo_match\r\n.*$libbar_match\(\r\n.*Shared library is missing\)?.*\r\n${gdb_prompt} $" {
|
|
|
|
+ if { $has_libfoo && $has_libbar } {
|
|
|
|
+ pass "matched libfoo and libbar"
|
|
|
|
+ } else {
|
|
|
|
+ fail "matched libfoo and libbar (has_libfoo = $has_libfoo, has_libbar = $has_libbar)"
|
2016-10-20 20:30:43 +00:00
|
|
|
+ }
|
2016-10-24 21:23:00 +00:00
|
|
|
+ }
|
|
|
|
+ -re ".*$libfoo_match\(\r\n.*Shared library is missing\)?.*\r\n${gdb_prompt} $" {
|
|
|
|
+ if { $has_libfoo && !$has_libbar } {
|
|
|
|
+ pass "matched libfoo"
|
|
|
|
+ } else {
|
|
|
|
+ fail "matched libfoo (has_libfoo = $has_libfoo, has_libbar = $has_libbar)"
|
2016-10-20 20:30:43 +00:00
|
|
|
+ }
|
2016-10-24 21:23:00 +00:00
|
|
|
+ }
|
|
|
|
+ -re ".*$libbar_match\(\r\n.*Shared library is missing\)?.*\r\n${gdb_prompt} $" {
|
|
|
|
+ if { $has_libbar && !$has_libfoo } {
|
|
|
|
+ pass "matched libbar"
|
|
|
|
+ } else {
|
|
|
|
+ fail "matched libbar (has_libfoo = $has_libfoo, has_libbar = $has_libbar)"
|
2016-10-20 20:30:43 +00:00
|
|
|
+ }
|
2016-10-24 21:23:00 +00:00
|
|
|
+ }
|
|
|
|
+ "\r\n${gdb_prompt} $" {
|
|
|
|
+ if { !$has_libfoo && !$has_libbar } {
|
|
|
|
+ pass "did not match libfoo nor libbar"
|
|
|
|
+ } else {
|
|
|
|
+ fail "did not match libfoo nor libbar (has_libfoo = $has_libfoo, has_libbar = $has_libbar)"
|
2016-10-20 20:30:43 +00:00
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+proc test_stop_on_solib_events { } {
|
|
|
|
+ set pass 0
|
|
|
|
+ # This variable holds the information about whether libfoo and
|
|
|
|
+ # libbar (respectively) are expected in the "info shared" output.
|
2016-10-24 21:23:00 +00:00
|
|
|
+ set solib_event_order { { 0 0 } { 0 0 } { 0 0 } { 0 1 } \
|
|
|
|
+ { 0 1 } { 0 0 } { 0 0 } { 0 1 } \
|
|
|
|
+ { 0 1 } { 0 0 } { 0 0 } { 0 1 } \
|
|
|
|
+ { 0 1 } { 0 0 } { 0 0 1 } { 1 1 } \
|
|
|
|
+ { 1 1 } { 1 0 } { 1 0 } { 1 1 } \
|
|
|
|
+ { 1 1 } { 1 0 1 } { 1 0 } { 1 0 } }
|
2016-10-20 20:30:43 +00:00
|
|
|
+
|
|
|
|
+ with_test_prefix "stop-on-solib-events" {
|
|
|
|
+ gdb_test_no_output "set stop-on-solib-events 1" "setting stop-on-solib-events"
|
|
|
|
+
|
|
|
|
+ gdb_run_cmd
|
2021-03-26 18:40:18 +00:00
|
|
|
+ gdb_test "" "Wait for first prompt"
|
2016-10-20 20:30:43 +00:00
|
|
|
+ foreach l $solib_event_order {
|
|
|
|
+ incr pass
|
2016-10-24 21:23:00 +00:00
|
|
|
+ with_test_prefix "pass #$pass" {
|
|
|
|
+ set should_be_corrupted [expr 0+0[lindex $l 2]]
|
|
|
|
+ do_test [lindex $l 0] [lindex $l 1]
|
|
|
|
+ set test "continue"
|
|
|
|
+ global gdb_prompt
|
|
|
|
+ gdb_test_multiple $test $test {
|
|
|
|
+ -re "\r\nwarning: Corrupted shared library list:.*\r\nStopped due to shared library event.*\r\n$gdb_prompt $" {
|
|
|
|
+ set corrupted 1
|
|
|
|
+ pass $test
|
|
|
|
+ }
|
|
|
|
+ -re "\r\nStopped due to shared library event.*\r\n$gdb_prompt $" {
|
|
|
|
+ set corrupted 0
|
|
|
|
+ pass $test
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ set test "corrupted=$corrupted but should_be_corrupted=$should_be_corrupted"
|
|
|
|
+ if {$corrupted == $should_be_corrupted} {
|
|
|
|
+ pass $test
|
|
|
|
+ } else {
|
|
|
|
+ fail $test
|
|
|
|
+ }
|
|
|
|
+ }
|
2016-10-20 20:30:43 +00:00
|
|
|
+ }
|
|
|
|
+ # In the last pass we do not expect to see libfoo or libbar.
|
|
|
|
+ incr pass
|
2016-10-24 21:23:00 +00:00
|
|
|
+ with_test_prefix "pass #$pass" {
|
|
|
|
+ do_test 0 0
|
|
|
|
+ }
|
2016-10-20 20:30:43 +00:00
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+test_stop_on_solib_events
|