Blame SOURCES/polkit-0.115-CVE-2021-4034.patch

f8388e
diff --git a/src/programs/pkcheck.c b/src/programs/pkcheck.c
f8388e
index f1bb4e1..aff4f60 100644
f8388e
--- a/src/programs/pkcheck.c
f8388e
+++ b/src/programs/pkcheck.c
f8388e
@@ -363,6 +363,12 @@ main (int argc, char *argv[])
f8388e
   local_agent_handle = NULL;
f8388e
   ret = 126;
f8388e
 
f8388e
+  if (argc < 1)
f8388e
+    {
f8388e
+      help();
f8388e
+      exit(1);
f8388e
+    }
f8388e
+
f8388e
   /* Disable remote file access from GIO. */
f8388e
   setenv ("GIO_USE_VFS", "local", 1);
f8388e
 
f8388e
diff --git a/src/programs/pkexec.c b/src/programs/pkexec.c
f8388e
index 7698c5c..d84dc57 100644
f8388e
--- a/src/programs/pkexec.c
f8388e
+++ b/src/programs/pkexec.c
f8388e
@@ -488,6 +488,17 @@ main (int argc, char *argv[])
f8388e
   pid_t pid_of_caller;
f8388e
   gpointer local_agent_handle;
f8388e
 
f8388e
+
f8388e
+  /*
f8388e
+   * If 'pkexec' is called wrong, just show help and bail out.
f8388e
+   */
f8388e
+  if (argc<1)
f8388e
+    {
f8388e
+      clearenv();
f8388e
+      usage(argc, argv);
f8388e
+      exit(1);
f8388e
+    }
f8388e
+
f8388e
   ret = 127;
f8388e
   authority = NULL;
f8388e
   subject = NULL;
f8388e
@@ -614,10 +625,10 @@ main (int argc, char *argv[])
f8388e
 
f8388e
       path = g_strdup (pwstruct.pw_shell);
f8388e
       if (!path)
f8388e
-	{
f8388e
+        {
f8388e
           g_printerr ("No shell configured or error retrieving pw_shell\n");
f8388e
           goto out;
f8388e
-	}
f8388e
+        }
f8388e
       /* If you change this, be sure to change the if (!command_line)
f8388e
 	 case below too */
f8388e
       command_line = g_strdup (path);
f8388e
@@ -636,7 +647,15 @@ main (int argc, char *argv[])
f8388e
           goto out;
f8388e
         }
f8388e
       g_free (path);
f8388e
-      argv[n] = path = s;
f8388e
+      path = s;
f8388e
+
f8388e
+      /* argc<2 and pkexec runs just shell, argv is guaranteed to be null-terminated.
f8388e
+       * /-less shell shouldn't happen, but let's be defensive and don't write to null-termination
f8388e
+       */
f8388e
+      if (argv[n] != NULL)
f8388e
+      {
f8388e
+        argv[n] = path;
f8388e
+      }
f8388e
     }
f8388e
   if (access (path, F_OK) != 0)
f8388e
     {