07ee5fb
commit a6daecbb32cf5fb0f71bdc14dddd35e7422dd4bb
07ee5fb
Author: Karel Klic <kklic@redhat.com>
07ee5fb
Date:   Tue Apr 13 14:57:20 2010 +0200
07ee5fb
07ee5fb
    do not catch perl/python crashes when the script is not of known package origin
07ee5fb
07ee5fb
diff --git a/src/Daemon/MiddleWare.cpp b/src/Daemon/MiddleWare.cpp
07ee5fb
index a0ead47..5c9ecb7 100644
07ee5fb
--- a/src/Daemon/MiddleWare.cpp
07ee5fb
+++ b/src/Daemon/MiddleWare.cpp
07ee5fb
@@ -594,43 +594,51 @@ void LoadOpenGPGPublicKey(const char* key)
07ee5fb
 }
07ee5fb
 
07ee5fb
 /**
07ee5fb
- * Get a package name from executable name and save
07ee5fb
- * package description to particular debugdump directory of a crash.
07ee5fb
- * @param pExecutable A name of crashed application.
07ee5fb
- * @param pDebugDumpDir A debugdump dir containing all necessary data.
07ee5fb
- * @return It return results of operation. See mw_result_t.
07ee5fb
+ * Returns the first full path argument in the command line or NULL.
07ee5fb
+ * Skips options are in form "-XXX".
07ee5fb
+ * Caller must delete the returned string using free().
07ee5fb
  */
07ee5fb
 static char *get_argv1_if_full_path(const char* cmdline)
07ee5fb
 {
07ee5fb
-    char *argv1 = (char*) strchr(cmdline, ' ');
07ee5fb
+    const char *argv1 = strpbrk(cmdline, " \t");
07ee5fb
     while (argv1 != NULL)
07ee5fb
     {
07ee5fb
         /* we found space in cmdline, so it might contain
07ee5fb
          * path to some script like:
07ee5fb
          * /usr/bin/python [-XXX] /usr/bin/system-control-network
07ee5fb
          */
07ee5fb
-        argv1++;
07ee5fb
-        if (*argv1 == '-')
07ee5fb
+        argv1++; /* skip the space */
07ee5fb
+        if (*argv1 == '-') /* skip arguments */
07ee5fb
         {
07ee5fb
             /* looks like -XXX in "perl -XXX /usr/bin/script.pl", skip */
07ee5fb
-            argv1 = strchr(argv1, ' ');
07ee5fb
+            argv1 = strpbrk(argv1, " \t");
07ee5fb
             continue;
07ee5fb
         }
07ee5fb
-        /* if the string following the space doesn't start
07ee5fb
-         * with '/' it's probably not a full path to script
07ee5fb
-         * and we can't use it to determine the package name
07ee5fb
-         */
07ee5fb
-        if (*argv1 != '/')
07ee5fb
+        else if (*argv1 == ' ' || *argv1 == '\t') /* skip multiple spaces */
07ee5fb
+            continue;
07ee5fb
+        else if (*argv1 != '/')
07ee5fb
         {
07ee5fb
-            return NULL;
07ee5fb
+            /* if the string following the space doesn't start
07ee5fb
+             * with '/' it's probably not a full path to script
07ee5fb
+             * and we can't use it to determine the package name
07ee5fb
+             */
07ee5fb
+            break;
07ee5fb
         }
07ee5fb
+
07ee5fb
+        /* cut the rest of cmdline arguments */
07ee5fb
         int len = strchrnul(argv1, ' ') - argv1;
07ee5fb
-        /* cut the cmdline arguments */
07ee5fb
-        argv1 = xstrndup(argv1, len);
07ee5fb
-        break;
07ee5fb
+        return xstrndup(argv1, len);
07ee5fb
     }
07ee5fb
-    return argv1;
07ee5fb
+    return NULL;
07ee5fb
 }
07ee5fb
+
07ee5fb
+/**
07ee5fb
+ * Get a package name from executable name and save
07ee5fb
+ * package description to particular debugdump directory of a crash.
07ee5fb
+ * @param pExecutable A name of crashed application.
07ee5fb
+ * @param pDebugDumpDir A debugdump dir containing all necessary data.
07ee5fb
+ * @return It return results of operation. See mw_result_t.
07ee5fb
+ */
07ee5fb
 static mw_result_t SavePackageDescriptionToDebugDump(
07ee5fb
                 const char *pExecutable,
07ee5fb
                 const char *cmdline,
07ee5fb
@@ -692,6 +700,7 @@ static mw_result_t SavePackageDescriptionToDebugDump(
07ee5fb
              * This will work only if the cmdline contains the whole path.
07ee5fb
              * Example: python /usr/bin/system-control-network
07ee5fb
              */
07ee5fb
+            bool knownOrigin = false;
07ee5fb
             char *script_name = get_argv1_if_full_path(cmdline);
07ee5fb
             if (script_name)
07ee5fb
             {
07ee5fb
@@ -707,9 +716,16 @@ static mw_result_t SavePackageDescriptionToDebugDump(
07ee5fb
                     rpm_pkg = script_pkg;
07ee5fb
                     scriptName = script_name;
07ee5fb
                     pExecutable = scriptName.c_str();
07ee5fb
+                    knownOrigin = true;
07ee5fb
                 }
07ee5fb
                 free(script_name);
07ee5fb
             }
07ee5fb
+
07ee5fb
+            if (!knownOrigin && !g_settings_bProcessUnpackaged)
07ee5fb
+            {
07ee5fb
+                log("Interpreter crashed, but no packaged script detected: '%s'", cmdline);
07ee5fb
+                return MW_PACKAGE_ERROR;
07ee5fb
+            }
07ee5fb
         }
07ee5fb
 
07ee5fb
         package = rpm_pkg;
07ee5fb
@@ -717,7 +733,7 @@ static mw_result_t SavePackageDescriptionToDebugDump(
07ee5fb
         VERB2 log("Package:'%s' short:'%s'", rpm_pkg, packageName.c_str());
07ee5fb
         free(rpm_pkg);
07ee5fb
 
07ee5fb
-	if (g_setBlackList.find(packageName) != g_setBlackList.end())
07ee5fb
+        if (g_setBlackList.find(packageName) != g_setBlackList.end())
07ee5fb
         {
07ee5fb
             log("Blacklisted package '%s'", packageName.c_str());
07ee5fb
             return MW_BLACKLISTED;
07ee5fb
@@ -838,8 +854,8 @@ static void RunAnalyzerActions(const char *pAnalyzer, const char *pDebugDumpDir,
07ee5fb
             if (!action)
07ee5fb
             {
07ee5fb
                 /* GetAction() already complained if no such plugin.
07ee5fb
-		 * If plugin exists but isn't an Action, it's not an error.
07ee5fb
-		 */
07ee5fb
+                 * If plugin exists but isn't an Action, it's not an error.
07ee5fb
+                 */
07ee5fb
                 continue;
07ee5fb
             }
07ee5fb
             try