mfabik / rpms / satyr

Forked from rpms/satyr 3 years ago
Clone

Blame SOURCES/0001-Anonymize-paths-in-frames.patch

11c2fb
From 0a71b956f2a778860cc35c83b051272f3f80cefc Mon Sep 17 00:00:00 2001
11c2fb
From: Matej Marusak <mmarusak@redhat.com>
11c2fb
Date: Thu, 5 Apr 2018 11:06:43 +0200
11c2fb
Subject: [PATCH] Anonymize paths in frames
11c2fb
11c2fb
Fixes abrt/libreport#523
11c2fb
11c2fb
Signed-off-by: Matej Marusak <mmarusak@redhat.com>
11c2fb
---
11c2fb
 include/utils.h                    |  3 +++
11c2fb
 lib/java_frame.c                   |  6 ++++++
11c2fb
 lib/js_frame.c                     |  1 +
11c2fb
 lib/normalize.c                    |  9 +++++++++
11c2fb
 lib/python_frame.c                 |  2 ++
11c2fb
 lib/ruby_frame.c                   |  2 ++
11c2fb
 lib/utils.c                        | 23 +++++++++++++++++++++++
11c2fb
 tests/java_frame.at                | 12 ++++++++++++
11c2fb
 tests/js_frame.at                  |  7 +++++++
11c2fb
 tests/python/python.py             |  8 ++++----
11c2fb
 tests/python_stacktraces/python-01 |  2 +-
11c2fb
 tests/ruby_frame.at                |  2 +-
11c2fb
 12 files changed, 71 insertions(+), 6 deletions(-)
11c2fb
11c2fb
diff --git a/include/utils.h b/include/utils.h
11c2fb
index 1c7984b..b36bc2c 100644
11c2fb
--- a/include/utils.h
11c2fb
+++ b/include/utils.h
11c2fb
@@ -406,6 +406,9 @@ sr_parse_os_release(const char *input,
11c2fb
                     void (*callback)(char*, char*, void*),
11c2fb
                     void *data);
11c2fb
 
11c2fb
+char*
11c2fb
+anonymize_path(char *file_name);
11c2fb
+
11c2fb
 /**
11c2fb
  * Demangles C++ symbol.
11c2fb
  * @returns
11c2fb
diff --git a/lib/java_frame.c b/lib/java_frame.c
11c2fb
index 8724b64..ea407bf 100644
11c2fb
--- a/lib/java_frame.c
11c2fb
+++ b/lib/java_frame.c
11c2fb
@@ -468,7 +468,10 @@ const char *sr_java_frame_parse_frame_url(struct sr_java_frame *frame, const cha
11c2fb
         sr_location_add(location, 0, sr_skip_char_cspan(&cursor, path_stop));
11c2fb
 
11c2fb
         if (mark != cursor)
11c2fb
+        {
11c2fb
             frame->class_path = sr_strndup(mark, cursor - mark);
11c2fb
+            frame->class_path = anonymize_path(frame->class_path);
11c2fb
+        }
11c2fb
     }
11c2fb
 
11c2fb
     if (*cursor != ']' && *cursor != '\n')
11c2fb
@@ -522,8 +525,11 @@ sr_java_frame_parse(const char **input,
11c2fb
             if (sr_java_frame_parse_is_native_method(mark))
11c2fb
                 frame->is_native = true;
11c2fb
             else if (!sr_java_frame_parse_is_unknown_source(mark))
11c2fb
+            {
11c2fb
                 /* DO NOT set file_name if input says that source isn't known */
11c2fb
                 frame->file_name = sr_strndup(mark, cursor - mark);
11c2fb
+                frame->file_name = anonymize_path(frame->file_name);
11c2fb
+            }
11c2fb
         }
11c2fb
 
11c2fb
         if (*cursor == ':')
11c2fb
diff --git a/lib/js_frame.c b/lib/js_frame.c
11c2fb
index cb29bd6..e9b6514 100644
11c2fb
--- a/lib/js_frame.c
11c2fb
+++ b/lib/js_frame.c
11c2fb
@@ -344,6 +344,7 @@ sr_js_frame_parse_v8(const char **input,
11c2fb
      * ^^^^^^^^^^^^^^^^^
11c2fb
      */
11c2fb
     frame->file_name = sr_strndup(local_input, token - local_input);
11c2fb
+    frame->file_name = anonymize_path(frame->file_name);
11c2fb
 
11c2fb
     location->column += sr_skip_char_cspan(&local_input, "\n");
11c2fb
 
11c2fb
diff --git a/lib/normalize.c b/lib/normalize.c
11c2fb
index d23e8f5..3973b3b 100644
11c2fb
--- a/lib/normalize.c
11c2fb
+++ b/lib/normalize.c
11c2fb
@@ -630,6 +630,15 @@ sr_normalize_core_thread(struct sr_core_thread *thread)
11c2fb
         frame = next_frame;
11c2fb
     }
11c2fb
 
11c2fb
+    /* Anonymize file_name if contains /home/<user>/...
11c2fb
+     */
11c2fb
+    frame = thread->frames;
11c2fb
+    while (frame)
11c2fb
+    {
11c2fb
+        frame->file_name = anonymize_path(frame->file_name);
11c2fb
+        frame = frame->next;
11c2fb
+    }
11c2fb
+
11c2fb
     /* If the first frame has address 0x0000 and its name is '??', it
11c2fb
      * is a dereferenced null, and we remove it. This frame is not
11c2fb
      * really invalid, but it affects stacktrace quality rating. See
11c2fb
diff --git a/lib/python_frame.c b/lib/python_frame.c
11c2fb
index 9287f3d..8453016 100644
11c2fb
--- a/lib/python_frame.c
11c2fb
+++ b/lib/python_frame.c
11c2fb
@@ -237,6 +237,8 @@ sr_python_frame_parse(const char **input,
11c2fb
         frame->file_name = inside;
11c2fb
     }
11c2fb
 
11c2fb
+    frame->file_name = anonymize_path(frame->file_name);
11c2fb
+
11c2fb
     location->column += strlen(frame->file_name);
11c2fb
 
11c2fb
     if (0 == sr_skip_string(&local_input, "\", line "))
11c2fb
diff --git a/lib/ruby_frame.c b/lib/ruby_frame.c
11c2fb
index 4926c63..76f17fe 100644
11c2fb
--- a/lib/ruby_frame.c
11c2fb
+++ b/lib/ruby_frame.c
11c2fb
@@ -258,6 +258,8 @@ sr_ruby_frame_parse(const char **input,
11c2fb
     /* Everything before the colon is the file name. */
11c2fb
     *p = '\0';
11c2fb
     frame->file_name = filename_lineno_in;
11c2fb
+    frame->file_name = anonymize_path(frame->file_name);
11c2fb
+
11c2fb
     filename_lineno_in = NULL;
11c2fb
 
11c2fb
     if(!sr_skip_char(&local_input, '`'))
11c2fb
diff --git a/lib/utils.c b/lib/utils.c
11c2fb
index 5bbbd19..415929c 100644
11c2fb
--- a/lib/utils.c
11c2fb
+++ b/lib/utils.c
11c2fb
@@ -31,6 +31,9 @@
11c2fb
 #include <fcntl.h>
11c2fb
 #include <ctype.h>
11c2fb
 
11c2fb
+#define ANONYMIZED_PATH "/home/anonymized"
11c2fb
+
11c2fb
+
11c2fb
 /* The prototype is in C++ header cxxabi.h, let's just copypaste it here
11c2fb
  * instead of fiddling with include directories */
11c2fb
 char* __cxa_demangle(const char* mangled_name, char* output_buffer,
11c2fb
@@ -849,3 +852,23 @@ sr_demangle_symbol(const char *sym)
11c2fb
 
11c2fb
     return demangled;
11c2fb
 }
11c2fb
+
11c2fb
+char*
11c2fb
+anonymize_path(char *orig_path)
11c2fb
+{
11c2fb
+    if (!orig_path)
11c2fb
+        return orig_path;
11c2fb
+    char* new_path = orig_path;
11c2fb
+    if (strncmp(orig_path, "/home/", strlen("/home/")) == 0)
11c2fb
+    {
11c2fb
+        new_path = strchr(new_path + strlen("/home/"), '/');
11c2fb
+        if (new_path)
11c2fb
+        {
11c2fb
+            // Join /home/anonymized/ and ^
11c2fb
+            new_path = sr_asprintf("%s%s", ANONYMIZED_PATH, new_path);
11c2fb
+            free(orig_path);
11c2fb
+            return new_path;
11c2fb
+        }
11c2fb
+    }
11c2fb
+    return orig_path;
11c2fb
+}
11c2fb
diff --git a/tests/java_frame.at b/tests/java_frame.at
11c2fb
index 00738be..2c6a7de 100644
11c2fb
--- a/tests/java_frame.at
11c2fb
+++ b/tests/java_frame.at
11c2fb
@@ -459,6 +459,18 @@ main(void)
11c2fb
   location.column = 0;
11c2fb
   check(c, &frame, c + strlen(c), &location);
11c2fb
 
11c2fb
+  /** next frame **/
11c2fb
+  sr_java_frame_init(&frame);
11c2fb
+  frame.name = sr_strdup("com.redhat.abrt.duke.nuke");
11c2fb
+  frame.file_name = sr_strdup("duke.java");
11c2fb
+  frame.class_path = sr_strdup("/home/anonymized/lib/java/foo.class");
11c2fb
+
11c2fb
+  c = "    at com.redhat.abrt.duke.nuke(duke.java:-1) [file:/home/user/lib/java/foo.class]\n";
11c2fb
+  sr_location_init(&location);
11c2fb
+  location.line = 2;
11c2fb
+  location.column = 0;
11c2fb
+  check(c, &frame, c + strlen(c), &location);
11c2fb
+
11c2fb
   /** next frame **/
11c2fb
   sr_java_frame_init(&frame);
11c2fb
   frame.name = sr_strdup("com.redhat.abrt.duke.nuke");
11c2fb
diff --git a/tests/js_frame.at b/tests/js_frame.at
11c2fb
index d17dd69..a3cc5d5 100644
11c2fb
--- a/tests/js_frame.at
11c2fb
+++ b/tests/js_frame.at
11c2fb
@@ -102,6 +102,13 @@ main(void)
11c2fb
                 33,
11c2fb
                 63);
11c2fb
 
11c2fb
+    check_valid("at    ContextifyScript.Script.runInThisContext    (/home/user/vm.js:25:33)",
11c2fb
+                "ContextifyScript.Script.runInThisContext",
11c2fb
+                "/home/anonymized/vm.js",
11c2fb
+                25,
11c2fb
+                33,
11c2fb
+                74);
11c2fb
+
11c2fb
     check_valid("at    ContextifyScript.Script.runInThisContext    (vm.js:25:33)  ",
11c2fb
                 "ContextifyScript.Script.runInThisContext",
11c2fb
                 "vm.js",
11c2fb
diff --git a/tests/python/python.py b/tests/python/python.py
11c2fb
index 9044200..77a9e59 100755
11c2fb
--- a/tests/python/python.py
11c2fb
+++ b/tests/python/python.py
11c2fb
@@ -6,7 +6,7 @@ from test_helpers import *
11c2fb
 path = '../python_stacktraces/python-01'
11c2fb
 contents = load_input_contents(path)
11c2fb
 frames_expected = 11
11c2fb
-expected_short_text = '''#1 _getPackage in /usr/share/PackageKit/helpers/yum/yumBackend.py:2534
11c2fb
+expected_short_text = '''#1 _getPackage in /home/anonymized/PackageKit/helpers/yum/yumBackend.py:2534
11c2fb
 #2 updateProgress in /usr/share/PackageKit/helpers/yum/yumBackend.py:2593
11c2fb
 #3 _do_start in /usr/share/PackageKit/helpers/yum/yumBackend.py:2551
11c2fb
 #4 start in /usr/lib/python2.6/site-packages/urlgrabber/progress.py:129
11c2fb
@@ -76,16 +76,16 @@ class TestPythonStacktrace(BindingsTestCase):
11c2fb
         self.assertEqual(self.trace.to_short_text(6), expected_short_text)
11c2fb
 
11c2fb
     def test_bthash(self):
11c2fb
-        self.assertEqual(self.trace.get_bthash(), 'fa0a7ff4b65f18661a6ce102eb787ff0d77ff12f')
11c2fb
+        self.assertEqual(self.trace.get_bthash(), 'eabeeae89433bb3b3d9eb8190659dcf057ab3cd1')
11c2fb
 
11c2fb
     def test_duphash(self):
11c2fb
         expected_plain = '''Thread
11c2fb
-/usr/share/PackageKit/helpers/yum/yumBackend.py:2534
11c2fb
+/home/anonymized/PackageKit/helpers/yum/yumBackend.py:2534
11c2fb
 /usr/share/PackageKit/helpers/yum/yumBackend.py:2593
11c2fb
 /usr/share/PackageKit/helpers/yum/yumBackend.py:2551
11c2fb
 '''
11c2fb
         self.assertEqual(self.trace.get_duphash(flags=satyr.DUPHASH_NOHASH, frames=3), expected_plain)
11c2fb
-        self.assertEqual(self.trace.get_duphash(), '2c8e509a33966a08df1dd8b2348e850d1bc5b776')
11c2fb
+        self.assertEqual(self.trace.get_duphash(), '8c8273cddf94e10fc0349284afcff8970056d9e5')
11c2fb
 
11c2fb
     def test_crash_thread(self):
11c2fb
         self.assertTrue(self.trace.crash_thread is self.trace)
11c2fb
diff --git a/tests/python_stacktraces/python-01 b/tests/python_stacktraces/python-01
11c2fb
index 58abbfc..ae5e72c 100644
11c2fb
--- a/tests/python_stacktraces/python-01
11c2fb
+++ b/tests/python_stacktraces/python-01
11c2fb
@@ -19,6 +19,6 @@ Traceback (most recent call last):
11c2fb
     self.updateProgress(name, 0.0, "", "")
11c2fb
   File "/usr/share/PackageKit/helpers/yum/yumBackend.py", line 2593, in updateProgress
11c2fb
     pkg = self._getPackage(name)
11c2fb
-  File "/usr/share/PackageKit/helpers/yum/yumBackend.py", line 2534, in _getPackage
11c2fb
+  File "/home/user/PackageKit/helpers/yum/yumBackend.py", line 2534, in _getPackage
11c2fb
     sections = name.rsplit('-', 2)
11c2fb
 AttributeError: 'NoneType' object has no attribute 'rsplit'
11c2fb
diff --git a/tests/ruby_frame.at b/tests/ruby_frame.at
11c2fb
index 1b1b9d0..cef5603 100644
11c2fb
--- a/tests/ruby_frame.at
11c2fb
+++ b/tests/ruby_frame.at
11c2fb
@@ -38,7 +38,7 @@ main(void)
11c2fb
         "/usr/share/ruby/vendor_ruby/will_crash.rb", 13, "func", false, 2, 1);
11c2fb
 
11c2fb
   check("/home/u/work/will:crash/will_crash.rb:30:in `block in <class:WillClass>'",
11c2fb
-        "/home/u/work/will:crash/will_crash.rb", 30, "class:WillClass", true, 1, 0);
11c2fb
+        "/home/anonymized/work/will:crash/will_crash.rb", 30, "class:WillClass", true, 1, 0);
11c2fb
 
11c2fb
   check("./will_ruby_raise:8:in `<main>'",
11c2fb
         "./will_ruby_raise", 8, "main", true, 0, 0);
11c2fb
-- 
11c2fb
2.17.1
11c2fb