From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7701 invoked by alias); 7 Jan 2014 20:23:26 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 7692 invoked by uid 89); 7 Jan 2014 20:23:26 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.1 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 07 Jan 2014 20:23:25 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s07KNOX4003180 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 7 Jan 2014 15:23:24 -0500 Received: from host2.jankratochvil.net (ovpn-116-30.ams2.redhat.com [10.36.116.30]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s07KNKoX019758 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO) for ; Tue, 7 Jan 2014 15:23:23 -0500 Date: Tue, 07 Jan 2014 20:23:00 -0000 From: Jan Kratochvil To: gdb-patches@sourceware.org Subject: [patch] Fix set auto-load safe-path false warning regression (PR 16216) Message-ID: <20140107202320.GA16517@host2.jankratochvil.net> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="YiEDa0DAkWCtVeE4" Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes X-SW-Source: 2014-01/txt/msg00163.txt.bz2 --YiEDa0DAkWCtVeE4 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 697 Hi, auto-load safe-path warning for non-existing libthread_db.so.1 https://sourceware.org/bugzilla/show_bug.cgi?id=16216 echo 'main(){}'|gcc -pthread -x c -;gdb -q -ex "set libthread-db-search-path $PWD"':$sdir:$pdir' -ex 'show libthread-db-search-path' -ex start ./a.out warning: File "/tmp/libthread_db.so.1" auto-loading has been declined by your `auto-load safe-path' set to "$debugdir:$datadir/auto-load:/usr/bin/mono-gdb.py". [...] Such warning should not be printed because the file /tmp/libthread_db.so.1 does not exist. It is safe as the open of non-existing file fails, so non-existing file cannot do any security harm. No regressions on x86_64-fedora20-linux-gnu. Thanks, Jan --YiEDa0DAkWCtVeE4 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline; filename="safe.patch" Content-length: 2774 gdb/ 2014-01-07 Jan Kratochvil PR threads/16216 * linux-thread-db.c (try_thread_db_load): Add parameter check_auto_load_safe. Move here the file_is_auto_load_safe call. (try_thread_db_load_from_pdir_1): Move it there from here. (try_thread_db_load_from_sdir): Update caller. (try_thread_db_load_from_dir): Move it there from here. diff --git a/gdb/linux-thread-db.c b/gdb/linux-thread-db.c index 692d574..0daf24c 100644 --- a/gdb/linux-thread-db.c +++ b/gdb/linux-thread-db.c @@ -838,7 +838,7 @@ try_thread_db_load_1 (struct thread_db_info *info) relative, or just LIBTHREAD_DB. */ static int -try_thread_db_load (const char *library) +try_thread_db_load (const char *library, int check_auto_load_safe) { void *handle; struct thread_db_info *info; @@ -846,6 +846,25 @@ try_thread_db_load (const char *library) if (libthread_db_debug) printf_unfiltered (_("Trying host libthread_db library: %s.\n"), library); + + if (check_auto_load_safe) + { + if (access (library, R_OK) != 0) + { + /* Do not print warnings by file_is_auto_load_safe if the library does + not exist at this place. */ + if (libthread_db_debug) + printf_unfiltered (_("open failed: %s.\n"), safe_strerror (errno)); + return 0; + } + + if (!file_is_auto_load_safe (library, _("auto-load: Loading libthread-db " + "library \"%s\" from explicit " + "directory.\n"), + library)) + return 0; + } + handle = dlopen (library, RTLD_NOW); if (handle == NULL) { @@ -919,12 +938,7 @@ try_thread_db_load_from_pdir_1 (struct objfile *obj, const char *subdir) } strcat (cp, LIBTHREAD_DB_SO); - if (!file_is_auto_load_safe (path, _("auto-load: Loading libthread-db " - "library \"%s\" from $pdir.\n"), - path)) - result = 0; - else - result = try_thread_db_load (path); + result = try_thread_db_load (path, 1); do_cleanups (cleanup); return result; @@ -970,7 +984,7 @@ try_thread_db_load_from_pdir (const char *subdir) static int try_thread_db_load_from_sdir (void) { - return try_thread_db_load (LIBTHREAD_DB_SO); + return try_thread_db_load (LIBTHREAD_DB_SO, 0); } /* Try to load libthread_db from directory DIR of length DIR_LEN. @@ -993,13 +1007,7 @@ try_thread_db_load_from_dir (const char *dir, size_t dir_len) path[dir_len] = '/'; strcpy (path + dir_len + 1, LIBTHREAD_DB_SO); - if (!file_is_auto_load_safe (path, _("auto-load: Loading libthread-db " - "library \"%s\" from explicit " - "directory.\n"), - path)) - result = 0; - else - result = try_thread_db_load (path); + result = try_thread_db_load (path, 1); do_cleanups (cleanup); return result; --YiEDa0DAkWCtVeE4--