Blame SOURCES/0045-gdb-disable-loading-of-auto-loaded-files.patch

a60cd7
From 5a2f83cd86ce824167fa7ea8e5357c014034ed46 Mon Sep 17 00:00:00 2001
a60cd7
From: Jakub Filak <jfilak@redhat.com>
a60cd7
Date: Mon, 9 Jun 2014 17:13:09 +0200
a60cd7
Subject: [ABRT PATCH 45/66] gdb: disable loading of auto-loaded files
a60cd7
a60cd7
https://sourceware.org/gdb/onlinedocs/gdb/Auto_002dloading.html
a60cd7
a60cd7
There are two main reasons for doing so:
a60cd7
1. we cannot trust anybody
a60cd7
  - the auto-loaded file may change the output format
a60cd7
  - security?
a60cd7
2. bugs in such a files (#817)
a60cd7
a60cd7
Resolves: #1128637
a60cd7
a60cd7
Signed-off-by: Jakub Filak <jfilak@redhat.com>
a60cd7
---
a60cd7
 src/lib/hooklib.c | 40 +++++++++++++++++++++-------------------
a60cd7
 1 file changed, 21 insertions(+), 19 deletions(-)
a60cd7
a60cd7
diff --git a/src/lib/hooklib.c b/src/lib/hooklib.c
a60cd7
index 4a50727..21ad9e0 100644
a60cd7
--- a/src/lib/hooklib.c
a60cd7
+++ b/src/lib/hooklib.c
a60cd7
@@ -252,10 +252,12 @@ char *get_backtrace(const char *dump_dir_name, unsigned timeout_sec, const char
a60cd7
     /* Let user know what's going on */
a60cd7
     log(_("Generating backtrace"));
a60cd7
 
a60cd7
-    char *args[21];
a60cd7
+    char *args[23];
a60cd7
     args[0] = (char*)"gdb";
a60cd7
     args[1] = (char*)"-batch";
a60cd7
     args[2] = (char*)"-ex";
a60cd7
+    args[3] = (char*)"set auto-load off";
a60cd7
+    args[4] = (char*)"-ex";
a60cd7
     struct strbuf *set_debug_file_directory = strbuf_new();
a60cd7
     if(debuginfo_dirs == NULL)
a60cd7
     {
a60cd7
@@ -278,7 +280,7 @@ char *get_backtrace(const char *dump_dir_name, unsigned timeout_sec, const char
a60cd7
             p = colon_or_nul;
a60cd7
         }
a60cd7
     }
a60cd7
-    args[3] = strbuf_free_nobuf(set_debug_file_directory);
a60cd7
+    args[5] = strbuf_free_nobuf(set_debug_file_directory);
a60cd7
 
a60cd7
     /* "file BINARY_FILE" is needed, without it gdb cannot properly
a60cd7
      * unwind the stack. Currently the unwind information is located
a60cd7
@@ -300,27 +302,27 @@ char *get_backtrace(const char *dump_dir_name, unsigned timeout_sec, const char
a60cd7
      * TODO: check mtimes on COREFILE and BINARY_FILE and not supply
a60cd7
      * BINARY_FILE if it is newer (to at least avoid gdb complaining).
a60cd7
      */
a60cd7
-    args[4] = (char*)"-ex";
a60cd7
-    args[5] = xasprintf("file %s", executable);
a60cd7
-    free(executable);
a60cd7
-
a60cd7
     args[6] = (char*)"-ex";
a60cd7
-    args[7] = xasprintf("core-file %s/"FILENAME_COREDUMP, dump_dir_name);
a60cd7
+    args[7] = xasprintf("file %s", executable);
a60cd7
+    free(executable);
a60cd7
 
a60cd7
     args[8] = (char*)"-ex";
a60cd7
-    /*args[9] = ... see below */
a60cd7
+    args[9] = xasprintf("core-file %s/"FILENAME_COREDUMP, dump_dir_name);
a60cd7
+
a60cd7
     args[10] = (char*)"-ex";
a60cd7
-    args[11] = (char*)"info sharedlib";
a60cd7
-    /* glibc's abort() stores its message in __abort_msg variable */
a60cd7
+    /*args[11] = ... see below */
a60cd7
     args[12] = (char*)"-ex";
a60cd7
-    args[13] = (char*)"print (char*)__abort_msg";
a60cd7
+    args[13] = (char*)"info sharedlib";
a60cd7
+    /* glibc's abort() stores its message in __abort_msg variable */
a60cd7
     args[14] = (char*)"-ex";
a60cd7
-    args[15] = (char*)"print (char*)__glib_assert_msg";
a60cd7
+    args[15] = (char*)"print (char*)__abort_msg";
a60cd7
     args[16] = (char*)"-ex";
a60cd7
-    args[17] = (char*)"info all-registers";
a60cd7
+    args[17] = (char*)"print (char*)__glib_assert_msg";
a60cd7
     args[18] = (char*)"-ex";
a60cd7
-    args[19] = (char*)"disassemble";
a60cd7
-    args[20] = NULL;
a60cd7
+    args[19] = (char*)"info all-registers";
a60cd7
+    args[20] = (char*)"-ex";
a60cd7
+    args[21] = (char*)"disassemble";
a60cd7
+    args[22] = NULL;
a60cd7
 
a60cd7
     /* Get the backtrace, but try to cap its size */
a60cd7
     /* Limit bt depth. With no limit, gdb sometimes OOMs the machine */
a60cd7
@@ -330,9 +332,9 @@ char *get_backtrace(const char *dump_dir_name, unsigned timeout_sec, const char
a60cd7
     char *bt = NULL;
a60cd7
     while (1)
a60cd7
     {
a60cd7
-        args[9] = xasprintf("%s backtrace %u%s", thread_apply_all, bt_depth, full);
a60cd7
+        args[11] = xasprintf("%s backtrace %u%s", thread_apply_all, bt_depth, full);
a60cd7
         bt = exec_vp(args, /*redirect_stderr:*/ 1, timeout_sec, NULL);
a60cd7
-        free(args[9]);
a60cd7
+        free(args[11]);
a60cd7
         if ((bt && strnlen(bt, 256*1024) < 256*1024) || bt_depth <= 32)
a60cd7
         {
a60cd7
             break;
a60cd7
@@ -357,7 +359,7 @@ char *get_backtrace(const char *dump_dir_name, unsigned timeout_sec, const char
a60cd7
          * End of assembler dump.
a60cd7
          * (IOW: "empty" dump)
a60cd7
          */
a60cd7
-        args[19] = (char*)"disassemble $pc-20, $pc+64";
a60cd7
+        args[21] = (char*)"disassemble $pc-20, $pc+64";
a60cd7
 
a60cd7
         if (bt_depth <= 64 && thread_apply_all[0] != '\0')
a60cd7
         {
a60cd7
@@ -373,9 +375,9 @@ char *get_backtrace(const char *dump_dir_name, unsigned timeout_sec, const char
a60cd7
         }
a60cd7
     }
a60cd7
 
a60cd7
-    free(args[3]);
a60cd7
     free(args[5]);
a60cd7
     free(args[7]);
a60cd7
+    free(args[9]);
a60cd7
     return bt;
a60cd7
 }
a60cd7
 
a60cd7
-- 
a60cd7
1.8.3.1
a60cd7