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