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