diff options
-rw-r--r-- | inc/abrtlib.h | 1 | ||||
-rw-r--r-- | lib/plugins/CCpp.cpp | 64 | ||||
-rw-r--r-- | lib/plugins/Makefile.am | 2 | ||||
-rw-r--r-- | lib/utils/Makefile.am | 1 | ||||
-rw-r--r-- | lib/utils/sha1.c (renamed from lib/plugins/CCpp_sha1.cpp) | 1 | ||||
-rw-r--r-- | lib/utils/sha1.h (renamed from lib/plugins/CCpp_sha1.h) | 8 |
6 files changed, 28 insertions, 49 deletions
diff --git a/inc/abrtlib.h b/inc/abrtlib.h index a1ad9c3d..2daf6005 100644 --- a/inc/abrtlib.h +++ b/inc/abrtlib.h @@ -77,6 +77,7 @@ int vdprintf(int d, const char *format, va_list ap); #include "strbuf.h" #include "crash_types.h" #include "dump_dir.h" +#include "sha1.h" #ifdef __cplusplus diff --git a/lib/plugins/CCpp.cpp b/lib/plugins/CCpp.cpp index 4b1590e5..b5181832 100644 --- a/lib/plugins/CCpp.cpp +++ b/lib/plugins/CCpp.cpp @@ -26,7 +26,6 @@ #include "comm_layer_inner.h" #include "Polkit.h" #include "backtrace.h" -#include "CCpp_sha1.h" using namespace std; @@ -53,42 +52,12 @@ CAnalyzerCCpp::CAnalyzerCCpp() : m_nGdbTimeoutSec(60) {} -static string create_hash(const char *pInput) +static void create_hash(char hash_str[SHA1_RESULT_LEN*2 + 1], const char *pInput) { - unsigned int len; - -#if 0 -{ - char hash_str[SHA1_LENGTH*2 + 1]; - unsigned char hash[SHA1_LENGTH]; - HASHContext *hc; - hc = HASH_Create(HASH_AlgSHA1); - if (!hc) - { - error_msg_and_die("HASH_Create(HASH_AlgSHA1) failed"); /* paranoia */ - } - HASH_Begin(hc); - HASH_Update(hc, (const unsigned char*)pInput, strlen(pInput)); - HASH_End(hc, hash, &len, sizeof(hash)); - HASH_Destroy(hc); - - char *d = hash_str; - unsigned char *s = hash; - while (len) - { - *d++ = "0123456789abcdef"[*s >> 4]; - *d++ = "0123456789abcdef"[*s & 0xf]; - s++; - len--; - } - *d = '\0'; -//log("hash1:%s str:'%s'", hash_str, pInput); -} -#endif - - char hash_str[SHA1_RESULT_LEN*2 + 1]; + unsigned len; unsigned char hash2[SHA1_RESULT_LEN]; sha1_ctx_t sha1ctx; + sha1_begin(&sha1ctx); sha1_hash(pInput, strlen(pInput), &sha1ctx); sha1_end(hash2, &sha1ctx); @@ -104,9 +73,7 @@ static string create_hash(const char *pInput) len--; } *d = '\0'; -//log("hash2:%s str:'%s'", hash_str, pInput); - - return hash_str; + //log("hash2:%s str:'%s'", hash_str, pInput); } /** @@ -297,8 +264,6 @@ static char *get_backtrace(const char *pDebugDumpDir, const char *pDebugInfoDirs bt_depth = 256; full = ""; } - free(bt); - free(args[9]); } free(uid); free(args[5]); @@ -363,7 +328,7 @@ static char* run_unstrip_n(const char *pDebugDumpDir, unsigned timeout_sec) /* Needs gdb feature from here: https://bugzilla.redhat.com/show_bug.cgi?id=528668 * It is slated to be in F12/RHEL6. * - * returened value must be freed + * returned value must be freed */ static char *install_debug_infos(const char *pDebugDumpDir, const char *debuginfo_dirs) { @@ -581,10 +546,11 @@ string CAnalyzerCCpp::GetLocalUUID(const char *pDebugDumpDir) free(package); free(executable); - string hash = create_hash(hash_str); + char hash_str2[SHA1_RESULT_LEN*2 + 1]; + create_hash(hash_str2, hash_str); free(hash_str); - return hash; + return hash_str2; } string CAnalyzerCCpp::GetGlobalUUID(const char *pDebugDumpDir) @@ -720,10 +686,11 @@ string CAnalyzerCCpp::GetGlobalUUID(const char *pDebugDumpDir) free(package); free(executable); - string hash = create_hash(hash_str); + char hash_str2[SHA1_RESULT_LEN*2 + 1]; + create_hash(hash_str2, hash_str); free(hash_str); - return hash; + return hash_str2; } } @@ -870,10 +837,11 @@ void CAnalyzerCCpp::CreateReport(const char *pDebugDumpDir, int force) struct strbuf *bt = backtrace_tree_as_str(backtrace, false); strbuf_prepend_str(bt, executable); strbuf_prepend_str(bt, package); - dd_save_text(dd, FILENAME_GLOBAL_UUID, create_hash(bt->buf).c_str()); + char hash_str[SHA1_RESULT_LEN*2 + 1]; + create_hash(hash_str, bt->buf); + dd_save_text(dd, FILENAME_GLOBAL_UUID, hash_str); strbuf_free(bt); - /* Compute and store backtrace rating. */ /* Compute and store backtrace rating. The crash frame is more important that the others. The frames around the crash are more important than the rest. */ @@ -910,7 +878,9 @@ void CAnalyzerCCpp::CreateReport(const char *pDebugDumpDir, int force) struct strbuf *ibt = independent_backtrace(backtrace_str); strbuf_prepend_str(ibt, executable); strbuf_prepend_str(ibt, package); - dd_save_text(dd, FILENAME_GLOBAL_UUID, create_hash(ibt->buf).c_str()); + char hash_str[SHA1_RESULT_LEN*2 + 1]; + create_hash(hash_str, ibt->buf); + dd_save_text(dd, FILENAME_GLOBAL_UUID, hash_str); strbuf_free(ibt); /* Compute and store backtrace rating. */ diff --git a/lib/plugins/Makefile.am b/lib/plugins/Makefile.am index ca874e1b..ffdfa332 100644 --- a/lib/plugins/Makefile.am +++ b/lib/plugins/Makefile.am @@ -64,7 +64,7 @@ INC_PATH=$(srcdir)/../../inc UTILS_PATH=$(srcdir)/../utils # CCpp -libCCpp_la_SOURCES = CCpp.cpp CCpp.h CCpp_sha1.cpp CCpp_sha1.h +libCCpp_la_SOURCES = CCpp.cpp CCpp.h libCCpp_la_LDFLAGS = -avoid-version #libCCpp_la_LIBADD = libCCpp_la_CPPFLAGS = -Wall -Werror \ diff --git a/lib/utils/Makefile.am b/lib/utils/Makefile.am index 15fd03e1..1e104821 100644 --- a/lib/utils/Makefile.am +++ b/lib/utils/Makefile.am @@ -32,6 +32,7 @@ libABRTUtils_la_SOURCES = \ strbuf.c strbuf.h \ abrt_packages.c abrt_packages.h \ hooklib.c hooklib.h \ + sha1.c sha1.h \ database.c libABRTUtils_la_CPPFLAGS = \ -Wall -Werror \ diff --git a/lib/plugins/CCpp_sha1.cpp b/lib/utils/sha1.c index 86a9e831..954e7bc8 100644 --- a/lib/plugins/CCpp_sha1.cpp +++ b/lib/utils/sha1.c @@ -18,7 +18,6 @@ * --------------------------------------------------------------------------- */ #include "abrtlib.h" -#include "CCpp_sha1.h" #if defined(__BIG_ENDIAN__) && __BIG_ENDIAN__ # define SHA1_BIG_ENDIAN 1 diff --git a/lib/plugins/CCpp_sha1.h b/lib/utils/sha1.h index abadfd92..02978ea4 100644 --- a/lib/plugins/CCpp_sha1.h +++ b/lib/utils/sha1.h @@ -18,6 +18,10 @@ * --------------------------------------------------------------------------- */ +#ifdef __cplusplus +extern "C" { +#endif + #define SHA1_RESULT_LEN (5 * 4) typedef struct sha1_ctx_t { @@ -30,3 +34,7 @@ typedef struct sha1_ctx_t { void sha1_begin(sha1_ctx_t *ctx); void sha1_hash(const void *buffer, size_t len, sha1_ctx_t *ctx); void sha1_end(void *resbuf, sha1_ctx_t *ctx); + +#ifdef __cplusplus +} +#endif |