CVE-2021-4034-pkexec-fix.patch 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. --- a/src/programs/pkcheck.c
  2. +++ a/src/programs/pkcheck.c
  3. @@ -363,6 +363,12 @@ main (int argc, char *argv[])
  4. local_agent_handle = NULL;
  5. ret = 126;
  6. + if (argc < 1)
  7. + {
  8. + help();
  9. + exit(1);
  10. + }
  11. +
  12. /* Disable remote file access from GIO. */
  13. setenv ("GIO_USE_VFS", "local", 1);
  14. --- a/src/programs/pkexec.c
  15. +++ a/src/programs/pkexec.c
  16. @@ -488,6 +488,17 @@ main (int argc, char *argv[])
  17. pid_t pid_of_caller;
  18. gpointer local_agent_handle;
  19. +
  20. + /*
  21. + * If 'pkexec' is called wrong, just show help and bail out.
  22. + */
  23. + if (argc<1)
  24. + {
  25. + clearenv();
  26. + usage(argc, argv);
  27. + exit(1);
  28. + }
  29. +
  30. ret = 127;
  31. authority = NULL;
  32. subject = NULL;
  33. @@ -614,10 +625,10 @@ main (int argc, char *argv[])
  34. path = g_strdup (pwstruct.pw_shell);
  35. if (!path)
  36. - {
  37. + {
  38. g_printerr ("No shell configured or error retrieving pw_shell\n");
  39. goto out;
  40. - }
  41. + }
  42. /* If you change this, be sure to change the if (!command_line)
  43. case below too */
  44. command_line = g_strdup (path);
  45. @@ -636,7 +647,15 @@ main (int argc, char *argv[])
  46. goto out;
  47. }
  48. g_free (path);
  49. - argv[n] = path = s;
  50. + path = s;
  51. +
  52. + /* argc<2 and pkexec runs just shell, argv is guaranteed to be null-terminated.
  53. + * /-less shell shouldn't happen, but let's be defensive and don't write to null-termination
  54. + */
  55. + if (argv[n] != NULL)
  56. + {
  57. + argv[n] = path;
  58. + }
  59. }
  60. if (access (path, F_OK) != 0)
  61. {