public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [patch] Fix set auto-load safe-path false warning regression (PR 16216)
@ 2014-01-07 20:23 Jan Kratochvil
  2014-01-13 20:12 ` Tom Tromey
  0 siblings, 1 reply; 3+ messages in thread
From: Jan Kratochvil @ 2014-01-07 20:23 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 697 bytes --]

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

[-- Attachment #2: safe.patch --]
[-- Type: text/plain, Size: 2774 bytes --]

gdb/
2014-01-07  Jan Kratochvil  <jan.kratochvil@redhat.com>

	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;

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [patch] Fix set auto-load safe-path false warning regression (PR 16216)
  2014-01-07 20:23 [patch] Fix set auto-load safe-path false warning regression (PR 16216) Jan Kratochvil
@ 2014-01-13 20:12 ` Tom Tromey
  2014-01-13 20:21   ` [commit+7.7] " Jan Kratochvil
  0 siblings, 1 reply; 3+ messages in thread
From: Tom Tromey @ 2014-01-13 20:12 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: gdb-patches

>>>>> "Jan" == Jan Kratochvil <jan.kratochvil@redhat.com> writes:

Jan> auto-load safe-path warning for non-existing libthread_db.so.1
Jan> https://sourceware.org/bugzilla/show_bug.cgi?id=16216

This looks reasonable to me.

Tom

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [commit+7.7] [patch] Fix set auto-load safe-path false warning regression (PR 16216)
  2014-01-13 20:12 ` Tom Tromey
@ 2014-01-13 20:21   ` Jan Kratochvil
  0 siblings, 0 replies; 3+ messages in thread
From: Jan Kratochvil @ 2014-01-13 20:21 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

On Mon, 13 Jan 2014 21:12:33 +0100, Tom Tromey wrote:
> >>>>> "Jan" == Jan Kratochvil <jan.kratochvil@redhat.com> writes:
> 
> Jan> auto-load safe-path warning for non-existing libthread_db.so.1
> Jan> https://sourceware.org/bugzilla/show_bug.cgi?id=16216
> 
> This looks reasonable to me.

Checked in:  fde4f8ed8ce077b652f046ada8b208eaccbf3a7a
and for 7.7: 46a3efa5a8d349612a4a121f518c8eb8d187ba2c


Thanks,
Jan

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-01-13 20:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-07 20:23 [patch] Fix set auto-load safe-path false warning regression (PR 16216) Jan Kratochvil
2014-01-13 20:12 ` Tom Tromey
2014-01-13 20:21   ` [commit+7.7] " Jan Kratochvil

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).