From dd92fc9b28a88ba47560d923064f88e2e523c505 Mon Sep 17 00:00:00 2001 From: Jiri Moskovcak Date: Tue, 15 Dec 2009 18:01:28 +0100 Subject: don't blame python for every crash in /usr/bin/python rhbz#533521 trac#109 - when there is a bug in 3rd party python extension, the python binary creates the coredump, so ABRT always blames the python package, but we want to blame the app that uses the extension instead --- src/Daemon/MiddleWare.cpp | 50 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) (limited to 'src/Daemon/MiddleWare.cpp') diff --git a/src/Daemon/MiddleWare.cpp b/src/Daemon/MiddleWare.cpp index b597a41..98feb7b 100644 --- a/src/Daemon/MiddleWare.cpp +++ b/src/Daemon/MiddleWare.cpp @@ -781,6 +781,33 @@ std::string getDebugDumpDir(const char *pUUID, return row.m_sDebugDumpDir; } +static char *guess_app_path(const char* cmdline) +{ + const char *path_start = NULL; + char *app_path = NULL; + // +1 to skip the space + path_start = strchr(cmdline, ' '); + /* we found space in cmdline, so it might contain + path to some script like: + /usr/bin/python /usr/bin/system-control-network + */ + if(path_start != NULL) + { + // skip the space + path_start++; + /* if the string following the space doesn't start + with '/' it's probably not a full path to app and + we can't use it to determine the package name + */ + if(*path_start == '/'){ + int len = strchrnul(path_start,' ') - path_start; + // cut the cmdline arguments + app_path = xstrndup(path_start, len); + } + } + return app_path; +} + mw_result_t SaveDebugDump(const char *pDebugDumpDir, map_crash_info_t& pCrashInfo) { @@ -788,6 +815,7 @@ mw_result_t SaveDebugDump(const char *pDebugDumpDir, std::string time; std::string analyzer; std::string executable; + std::string cmdline; try { CDebugDump dd; @@ -796,6 +824,7 @@ mw_result_t SaveDebugDump(const char *pDebugDumpDir, dd.LoadText(FILENAME_UID, UID); dd.LoadText(FILENAME_ANALYZER, analyzer); dd.LoadText(FILENAME_EXECUTABLE, executable); + dd.LoadText(FILENAME_CMDLINE, cmdline); } catch (CABRTException& e) { @@ -811,12 +840,31 @@ mw_result_t SaveDebugDump(const char *pDebugDumpDir, { return MW_IN_DB; } - mw_result_t res = SavePackageDescriptionToDebugDump(executable.c_str(), pDebugDumpDir); + /* first try to find package for the application guessed from cmdline + this will work only of the cmdline contains the whole path to the aplication + like: + /usr/bin/python /usr/bin/system-control-network + */ + mw_result_t res = MW_PACKAGE_ERROR; + char *application = guess_app_path(cmdline.c_str()); + if(application != NULL) + { + res = SavePackageDescriptionToDebugDump(application, pDebugDumpDir); + free(application); + } + if(res != MW_OK) + /* we didn't find the package, so the guess was probably wrong + try again with the executable + */ + { + res = SavePackageDescriptionToDebugDump(executable.c_str(), pDebugDumpDir); + } if (res != MW_OK) { return res; } + std::string lUUID = GetLocalUUID(analyzer.c_str(), pDebugDumpDir); const char *uid_str = analyzer_has_InformAllUsers(analyzer.c_str()) ? "-1" -- cgit From 060f38febbd01f1bb7e343bb33c85ff0aa0f30cd Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 15 Dec 2009 18:05:51 +0100 Subject: move misplaced comment Signed-off-by: Denys Vlasenko --- src/Daemon/MiddleWare.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'src/Daemon/MiddleWare.cpp') diff --git a/src/Daemon/MiddleWare.cpp b/src/Daemon/MiddleWare.cpp index 98feb7b..eb60ce4 100644 --- a/src/Daemon/MiddleWare.cpp +++ b/src/Daemon/MiddleWare.cpp @@ -783,23 +783,24 @@ std::string getDebugDumpDir(const char *pUUID, static char *guess_app_path(const char* cmdline) { - const char *path_start = NULL; + const char *path_start; char *app_path = NULL; - // +1 to skip the space + path_start = strchr(cmdline, ' '); - /* we found space in cmdline, so it might contain - path to some script like: - /usr/bin/python /usr/bin/system-control-network - */ - if(path_start != NULL) + if (path_start != NULL) { - // skip the space + /* we found space in cmdline, so it might contain + path to some script like: + /usr/bin/python /usr/bin/system-control-network + */ + /* +1 to skip the space */ path_start++; /* if the string following the space doesn't start with '/' it's probably not a full path to app and we can't use it to determine the package name */ - if(*path_start == '/'){ + if (*path_start == '/') + { int len = strchrnul(path_start,' ') - path_start; // cut the cmdline arguments app_path = xstrndup(path_start, len); -- cgit From 1e119f37b85b90c5a9a17fdcbc80625727b4ab66 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 15 Dec 2009 19:54:51 +0100 Subject: fix all instances of atoi() usage Signed-off-by: Denys Vlasenko --- src/Daemon/MiddleWare.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Daemon/MiddleWare.cpp') diff --git a/src/Daemon/MiddleWare.cpp b/src/Daemon/MiddleWare.cpp index eb60ce4..fd2e86b 100644 --- a/src/Daemon/MiddleWare.cpp +++ b/src/Daemon/MiddleWare.cpp @@ -477,7 +477,7 @@ report_status_t Report(const map_crash_report_t& pCrashReport, if (pUID != "") { - home = get_home_dir(atoi(pUID.c_str())); + home = get_home_dir(xatoi_u(pUID.c_str())); if (home != "") { oldSettings = reporter->GetSettings(); -- cgit From 65f8b90b01693e467359b7258d98ac64d7807c3f Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 16 Dec 2009 16:10:12 +0100 Subject: change "python /path/to/script" code a bit: doesnt log false failures now Signed-off-by: Denys Vlasenko --- src/Daemon/MiddleWare.cpp | 120 ++++++++++++++++++++++++++-------------------- 1 file changed, 67 insertions(+), 53 deletions(-) (limited to 'src/Daemon/MiddleWare.cpp') diff --git a/src/Daemon/MiddleWare.cpp b/src/Daemon/MiddleWare.cpp index fd2e86b..6b8bfcc 100644 --- a/src/Daemon/MiddleWare.cpp +++ b/src/Daemon/MiddleWare.cpp @@ -563,11 +563,38 @@ void LoadOpenGPGPublicKey(const char* key) * @param pDebugDumpDir A debugdump dir containing all necessary data. * @return It return results of operation. See mw_result_t. */ -static mw_result_t SavePackageDescriptionToDebugDump(const char *pExecutable, - const char *pDebugDumpDir) +static char *get_argv1_if_full_path(const char* cmdline) +{ + char *argv1 = (char*) strchr(cmdline, ' '); + if (argv1 != NULL) + { + /* we found space in cmdline, so it might contain + * path to some script like: + * /usr/bin/python /usr/bin/system-control-network + */ + argv1++; + /* if the string following the space doesn't start + * with '/' it's probably not a full path to script + * and we can't use it to determine the package name + */ + if (*argv1 != '/') + { + return NULL; + } + int len = strchrnul(argv1, ' ') - argv1; + /* cut the cmdline arguments */ + argv1 = xstrndup(argv1, len); + } + return argv1; +} +static mw_result_t SavePackageDescriptionToDebugDump( + const char *pExecutable, + const char *cmdline, + const char *pDebugDumpDir) { std::string package; std::string packageName; + std::string scriptName; /* only if "interpreter /path/to/script" */ if (strcmp(pExecutable, "kernel") == 0) { @@ -582,6 +609,42 @@ static mw_result_t SavePackageDescriptionToDebugDump(const char *pExecutable, return MW_PACKAGE_ERROR; } + /* Check well-known interpreter names */ + + const char *basename = strrchr(pExecutable, '/'); + if (basename) basename++; else basename = pExecutable; + + /* Add "perl" and such as needed */ + if (strcmp(basename, "python") == 0) + { +// TODO: we don't verify that python executable is not modified +// or that python package is properly signed +// (see CheckFingerprint/CheckHash below) + + /* Try to find package for the script by looking at argv[1]. + * This will work only of the cmdline contains the whole path. + * Example: python /usr/bin/system-control-network + */ + char *script_name = get_argv1_if_full_path(cmdline); + if (script_name) + { + char *script_pkg = GetPackage(script_name); + if (script_pkg) + { + /* There is a well-formed script name in argv[1], + * and it does belong to some package. + * Replace interpreter's rpm_pkg and pExecutable + * with data pertaining to the script. + */ + free(rpm_pkg); + rpm_pkg = script_pkg; + scriptName = script_name; + pExecutable = scriptName.c_str(); + } + free(script_name); + } + } + package = rpm_pkg; packageName = package.substr(0, package.rfind("-", package.rfind("-") - 1)); VERB2 log("Package:'%s' short:'%s'", rpm_pkg, packageName.c_str()); @@ -610,10 +673,7 @@ static mw_result_t SavePackageDescriptionToDebugDump(const char *pExecutable, } std::string description = GetDescription(packageName.c_str()); -//TODO: if executable in /usr/bin/python, /bin/sh and such, -//we need to extract component using argv[1] std::string component = GetComponent(pExecutable); - try { CDebugDump dd; @@ -781,34 +841,6 @@ std::string getDebugDumpDir(const char *pUUID, return row.m_sDebugDumpDir; } -static char *guess_app_path(const char* cmdline) -{ - const char *path_start; - char *app_path = NULL; - - path_start = strchr(cmdline, ' '); - if (path_start != NULL) - { - /* we found space in cmdline, so it might contain - path to some script like: - /usr/bin/python /usr/bin/system-control-network - */ - /* +1 to skip the space */ - path_start++; - /* if the string following the space doesn't start - with '/' it's probably not a full path to app and - we can't use it to determine the package name - */ - if (*path_start == '/') - { - int len = strchrnul(path_start,' ') - path_start; - // cut the cmdline arguments - app_path = xstrndup(path_start, len); - } - } - return app_path; -} - mw_result_t SaveDebugDump(const char *pDebugDumpDir, map_crash_info_t& pCrashInfo) { @@ -841,31 +873,13 @@ mw_result_t SaveDebugDump(const char *pDebugDumpDir, { return MW_IN_DB; } - /* first try to find package for the application guessed from cmdline - this will work only of the cmdline contains the whole path to the aplication - like: - /usr/bin/python /usr/bin/system-control-network - */ - mw_result_t res = MW_PACKAGE_ERROR; - char *application = guess_app_path(cmdline.c_str()); - if(application != NULL) - { - res = SavePackageDescriptionToDebugDump(application, pDebugDumpDir); - free(application); - } - if(res != MW_OK) - /* we didn't find the package, so the guess was probably wrong - try again with the executable - */ - { - res = SavePackageDescriptionToDebugDump(executable.c_str(), pDebugDumpDir); - } + + mw_result_t res = SavePackageDescriptionToDebugDump(executable.c_str(), cmdline.c_str(), pDebugDumpDir); if (res != MW_OK) { return res; } - std::string lUUID = GetLocalUUID(analyzer.c_str(), pDebugDumpDir); const char *uid_str = analyzer_has_InformAllUsers(analyzer.c_str()) ? "-1" -- cgit