You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
2.3 KiB

  1. From 9f23ba5a40b42acf4463b593bffd73caee8b527c Mon Sep 17 00:00:00 2001
  2. From: Rosen Penev <rosenp@gmail.com>
  3. Date: Sun, 15 Jul 2018 20:43:44 -0700
  4. Subject: [PATCH] Replace strndupa with strcpy
  5. glibc only. A static string is better.
  6. Signed-off-by: Rosen Penev <rosenp@gmail.com>
  7. ---
  8. modules/pam_exec/pam_exec.c | 31 +++++++++++--------------------
  9. 1 file changed, 11 insertions(+), 20 deletions(-)
  10. diff --git a/modules/pam_exec/pam_exec.c b/modules/pam_exec/pam_exec.c
  11. index 0ab6548..2fbab4f 100644
  12. --- a/modules/pam_exec/pam_exec.c
  13. +++ b/modules/pam_exec/pam_exec.c
  14. @@ -102,7 +102,7 @@ call_exec (const char *pam_type, pam_handle_t *pamh,
  15. int use_stdout = 0;
  16. int optargc;
  17. const char *logfile = NULL;
  18. - const char *authtok = NULL;
  19. + char authtok[PAM_MAX_RESP_SIZE];
  20. pid_t pid;
  21. int fds[2];
  22. int stdout_fds[2];
  23. @@ -180,12 +180,12 @@ call_exec (const char *pam_type, pam_handle_t *pamh,
  24. if (resp)
  25. {
  26. pam_set_item (pamh, PAM_AUTHTOK, resp);
  27. - authtok = strndupa (resp, PAM_MAX_RESP_SIZE);
  28. + strcpy (authtok, resp);
  29. _pam_drop (resp);
  30. }
  31. }
  32. else
  33. - authtok = strndupa (void_pass, PAM_MAX_RESP_SIZE);
  34. + strcpy (authtok, void_pass);
  35. if (pipe(fds) != 0)
  36. {
  37. @@ -225,23 +225,14 @@ call_exec (const char *pam_type, pam_handle_t *pamh,
  38. if (expose_authtok) /* send the password to the child */
  39. {
  40. - if (authtok != NULL)
  41. - { /* send the password to the child */
  42. - if (debug)
  43. - pam_syslog (pamh, LOG_DEBUG, "send password to child");
  44. - if (write(fds[1], authtok, strlen(authtok)+1) == -1)
  45. - pam_syslog (pamh, LOG_ERR,
  46. - "sending password to child failed: %m");
  47. - authtok = NULL;
  48. - }
  49. - else
  50. - {
  51. - if (write(fds[1], "", 1) == -1) /* blank password */
  52. - pam_syslog (pamh, LOG_ERR,
  53. - "sending password to child failed: %m");
  54. - }
  55. - close(fds[0]); /* close here to avoid possible SIGPIPE above */
  56. - close(fds[1]);
  57. + if (debug)
  58. + pam_syslog (pamh, LOG_DEBUG, "send password to child");
  59. + if (write(fds[1], authtok, strlen(authtok)) == -1)
  60. + pam_syslog (pamh, LOG_ERR,
  61. + "sending password to child failed: %m");
  62. +
  63. + close(fds[0]); /* close here to avoid possible SIGPIPE above */
  64. + close(fds[1]);
  65. }
  66. if (use_stdout)
  67. --
  68. 2.19.1