5f74b5e407
Signed-off-by: Igor Raits <ignatenkobrain@fedoraproject.org>
169 lines
6.0 KiB
Diff
169 lines
6.0 KiB
Diff
From 16468b57579997971c056687ecc8438a406d57c2 Mon Sep 17 00:00:00 2001
|
||
From: Ernestas Kulik <ekulik@redhat.com>
|
||
Date: Tue, 14 Jan 2020 16:36:21 +0100
|
||
Subject: [PATCH] Use GChecksum to compute checksums
|
||
MIME-Version: 1.0
|
||
Content-Type: text/plain; charset=UTF-8
|
||
Content-Transfer-Encoding: 8bit
|
||
|
||
d605ffeaa6ae411ef396160ffd67b7a6fd27c6ba in libreport removed some
|
||
convenience API for hashing data, so let’s just go with what GLib has in
|
||
store.
|
||
---
|
||
src/dbus/abrt_problems2_service.c | 33 +++++++++++----------
|
||
src/plugins/abrt-action-analyze-backtrace.c | 8 +++--
|
||
src/plugins/abrt-action-analyze-c.c | 7 +++--
|
||
src/plugins/abrt-action-analyze-python.c | 9 +++---
|
||
4 files changed, 32 insertions(+), 25 deletions(-)
|
||
|
||
diff --git a/src/dbus/abrt_problems2_service.c b/src/dbus/abrt_problems2_service.c
|
||
index 2511136f..a0d2a3ce 100644
|
||
--- a/src/dbus/abrt_problems2_service.c
|
||
+++ b/src/dbus/abrt_problems2_service.c
|
||
@@ -572,9 +572,11 @@ static AbrtP2Object *session_object_register(AbrtP2Service *service,
|
||
|
||
static char *session_object_caller_to_path(const char *caller)
|
||
{
|
||
- char hash_str[SHA1_RESULT_LEN*2 + 1];
|
||
- str_to_sha1str(hash_str, caller);
|
||
- return xasprintf(ABRT_P2_PATH"/Session/%s", hash_str);
|
||
+ g_autofree char *checksum = NULL;
|
||
+
|
||
+ checksum = g_compute_checksum_for_string(G_CHECKSUM_SHA1, caller, -1);
|
||
+
|
||
+ return xasprintf(ABRT_P2_PATH"/Session/%s", checksum);
|
||
}
|
||
|
||
static AbrtP2Object *abrt_p2_service_get_session_for_caller(
|
||
@@ -1323,9 +1325,11 @@ static void entry_object_destructor(AbrtP2Object *obj)
|
||
|
||
static char *entry_object_dir_name_to_path(const char *dd_dirname)
|
||
{
|
||
- char hash_str[SHA1_RESULT_LEN*2 + 1];
|
||
- str_to_sha1str(hash_str, dd_dirname);
|
||
- return xasprintf(ABRT_P2_PATH"/Entry/%s", hash_str);
|
||
+ g_autofree char *checksum = NULL;
|
||
+
|
||
+ checksum = g_compute_checksum_for_string(G_CHECKSUM_SHA1, dd_dirname, -1);
|
||
+
|
||
+ return xasprintf(ABRT_P2_PATH"/Entry/%s", checksum);
|
||
}
|
||
|
||
static AbrtP2Object *entry_object_register_dump_dir(AbrtP2Service *service,
|
||
@@ -1480,8 +1484,10 @@ char *abrt_p2_service_save_problem( AbrtP2Service *service,
|
||
else
|
||
{
|
||
/* start hash */
|
||
- sha1_ctx_t sha1ctx;
|
||
- sha1_begin(&sha1ctx);
|
||
+ g_autoptr(GChecksum) checksum = NULL;
|
||
+ const char *digest;
|
||
+
|
||
+ checksum = g_checksum_new(G_CHECKSUM_SHA1);
|
||
|
||
/*
|
||
* To avoid spurious hash differences, sort keys so that elements are
|
||
@@ -1500,19 +1506,16 @@ char *abrt_p2_service_save_problem( AbrtP2Service *service,
|
||
|
||
gsize size = 0;
|
||
const char *content = g_variant_get_string(element, &size);
|
||
- sha1_hash(&sha1ctx, content, size);
|
||
+
|
||
+ g_checksum_update(checksum, (const unsigned char *)content, size);
|
||
|
||
g_variant_unref(element);
|
||
}
|
||
g_list_free_full(list, free);
|
||
|
||
- /* end hash */
|
||
- char hash_bytes[SHA1_RESULT_LEN];
|
||
- sha1_end(&sha1ctx, hash_bytes);
|
||
- char hash_str[SHA1_RESULT_LEN*2 + 1];
|
||
- bin2hex(hash_str, hash_bytes, SHA1_RESULT_LEN)[0] = '\0';
|
||
+ digest = g_checksum_get_string(checksum);
|
||
|
||
- g_variant_dict_insert(&pd, FILENAME_UUID, "s", hash_str);
|
||
+ g_variant_dict_insert(&pd, FILENAME_UUID, "s", digest);
|
||
}
|
||
}
|
||
|
||
diff --git a/src/plugins/abrt-action-analyze-backtrace.c b/src/plugins/abrt-action-analyze-backtrace.c
|
||
index 622d7953..20e71945 100644
|
||
--- a/src/plugins/abrt-action-analyze-backtrace.c
|
||
+++ b/src/plugins/abrt-action-analyze-backtrace.c
|
||
@@ -82,6 +82,8 @@ int main(int argc, char **argv)
|
||
/* Store backtrace hash */
|
||
if (!backtrace)
|
||
{
|
||
+ g_autofree char *checksum = NULL;
|
||
+
|
||
/*
|
||
* The parser failed. Compute the duphash from the executable
|
||
* instead of a backtrace.
|
||
@@ -98,10 +100,10 @@ int main(int argc, char **argv)
|
||
strbuf_prepend_str(emptybt, component);
|
||
|
||
log_debug("Generating duphash: %s", emptybt->buf);
|
||
- char hash_str[SHA1_RESULT_LEN*2 + 1];
|
||
- str_to_sha1str(hash_str, emptybt->buf);
|
||
|
||
- dd_save_text(dd, FILENAME_DUPHASH, hash_str);
|
||
+ checksum = g_compute_checksum_for_string(G_CHECKSUM_SHA1, emptybt->buf, -1);
|
||
+
|
||
+ dd_save_text(dd, FILENAME_DUPHASH, checksum);
|
||
/*
|
||
* Other parts of ABRT assume that if no rating is available,
|
||
* it is ok to allow reporting of the bug. To be sure no bad
|
||
diff --git a/src/plugins/abrt-action-analyze-c.c b/src/plugins/abrt-action-analyze-c.c
|
||
index 08e48779..4a6d34d4 100644
|
||
--- a/src/plugins/abrt-action-analyze-c.c
|
||
+++ b/src/plugins/abrt-action-analyze-c.c
|
||
@@ -235,10 +235,11 @@ int main(int argc, char **argv)
|
||
|
||
log_debug("String to hash: %s", string_to_hash);
|
||
|
||
- char hash_str[SHA1_RESULT_LEN*2 + 1];
|
||
- str_to_sha1str(hash_str, string_to_hash);
|
||
+ g_autofree char *checksum = NULL;
|
||
|
||
- dd_save_text(dd, FILENAME_UUID, hash_str);
|
||
+ checksum = g_compute_checksum_for_string(G_CHECKSUM_SHA1, string_to_hash, -1);
|
||
+
|
||
+ dd_save_text(dd, FILENAME_UUID, checksum);
|
||
|
||
/* Create crash_function element from core_backtrace */
|
||
char *core_backtrace_json = dd_load_text_ext(dd, FILENAME_CORE_BACKTRACE,
|
||
diff --git a/src/plugins/abrt-action-analyze-python.c b/src/plugins/abrt-action-analyze-python.c
|
||
index 0dd55750..10589cbb 100644
|
||
--- a/src/plugins/abrt-action-analyze-python.c
|
||
+++ b/src/plugins/abrt-action-analyze-python.c
|
||
@@ -26,6 +26,8 @@
|
||
|
||
int main(int argc, char **argv)
|
||
{
|
||
+ g_autofree char *checksum = NULL;
|
||
+
|
||
/* I18n */
|
||
setlocale(LC_ALL, "");
|
||
#if ENABLE_NLS
|
||
@@ -91,13 +93,12 @@ int main(int argc, char **argv)
|
||
|
||
char *bt_end = strchrnul(bt, '\n');
|
||
*bt_end = '\0';
|
||
- char hash_str[SHA1_RESULT_LEN*2 + 1];
|
||
- str_to_sha1str(hash_str, bt);
|
||
+ checksum = g_compute_checksum_for_string(G_CHECKSUM_SHA1, bt, -1);
|
||
|
||
free(bt);
|
||
|
||
- dd_save_text(dd, FILENAME_UUID, hash_str);
|
||
- dd_save_text(dd, FILENAME_DUPHASH, hash_str);
|
||
+ dd_save_text(dd, FILENAME_UUID, checksum);
|
||
+ dd_save_text(dd, FILENAME_DUPHASH, checksum);
|
||
dd_close(dd);
|
||
|
||
return 0;
|
||
--
|
||
2.25.0
|
||
|