File 0001-polkit-0.96-cve-2021-4034.patch of Package polkit
From 3f2d6740c64db3d43ef6c8132be55ab6ec86f5cc Mon Sep 17 00:00:00 2001
From: Wang Long <w@laoqinren.net>
Date: Wed, 26 Jan 2022 21:40:20 +0800
Subject: [PATCH] polkit 0.96 cve-2021-4034
Signed-off-by: Wang Long <w@laoqinren.net>
---
src/programs/pkcheck.c | 6 ++++++
src/programs/pkexec.c | 20 +++++++++++++++++++-
2 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/src/programs/pkcheck.c b/src/programs/pkcheck.c
index fbda073..25c8749 100644
--- a/src/programs/pkcheck.c
+++ b/src/programs/pkcheck.c
@@ -93,6 +93,12 @@ main (int argc, char *argv[])
allow_user_interaction = FALSE;
ret = 126;
+ if (argc < 1)
+ {
+ help();
+ exit(1);
+ }
+
g_type_init ();
details = polkit_details_new ();
diff --git a/src/programs/pkexec.c b/src/programs/pkexec.c
index 860e665..acc0633 100644
--- a/src/programs/pkexec.c
+++ b/src/programs/pkexec.c
@@ -413,6 +413,16 @@ main (int argc, char *argv[])
uid_t uid_of_caller;
struct stat statbuf;
+ /*
+ * If 'pkexec' is called wrong, just show help and bail out.
+ */
+ if (argc<1)
+ {
+ clearenv();
+ usage(argc, argv);
+ exit(1);
+ }
+
ret = 127;
authority = NULL;
subject = NULL;
@@ -518,7 +528,15 @@ main (int argc, char *argv[])
goto out;
}
g_free (path);
- argv[n] = path = s;
+ path = s;
+
+ /* argc<2 and pkexec runs just shell, argv is guaranteed to be null-terminated.
+ * /-less shell shouldn't happen, but let's be defensive and don't write to null-termination
+ */
+ if (argv[n] != NULL)
+ {
+ argv[n] = path;
+ }
}
if (stat (path, &statbuf) != 0)
{
--
1.8.3.1