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

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