Index: Linux-PAM-1.1.5/modules/pam_exec/pam_exec.8.xml
===================================================================
--- Linux-PAM-1.1.5.orig/modules/pam_exec/pam_exec.8.xml
+++ Linux-PAM-1.1.5/modules/pam_exec/pam_exec.8.xml
@@ -100,7 +100,8 @@
               During authentication the calling command can read
               the password from <citerefentry>
               <refentrytitle>stdin</refentrytitle><manvolnum>3</manvolnum>
-              </citerefentry>.
+              </citerefentry>. Only first <emphasis>PAM_MAX_RESP_SIZE</emphasis>
+              bytes of a password are provided to the command.
             </para>
           </listitem>
         </varlistentry>
Index: Linux-PAM-1.1.5/modules/pam_exec/pam_exec.c
===================================================================
--- Linux-PAM-1.1.5.orig/modules/pam_exec/pam_exec.c
+++ Linux-PAM-1.1.5/modules/pam_exec/pam_exec.c
@@ -150,11 +150,11 @@ call_exec (const char *pam_type, pam_han
 		}
 
 	      pam_set_item (pamh, PAM_AUTHTOK, resp);
-	      authtok = strdupa (resp);
+	      authtok = strndupa (resp, PAM_MAX_RESP_SIZE);
 	      _pam_drop (resp);
 	    }
 	  else
-	    authtok = void_pass;
+	    authtok = strndupa (void_pass, PAM_MAX_RESP_SIZE);
 
 	  if (pipe(fds) != 0)
 	    {
Index: Linux-PAM-1.1.5/modules/pam_unix/pam_unix.8.xml
===================================================================
--- Linux-PAM-1.1.5.orig/modules/pam_unix/pam_unix.8.xml
+++ Linux-PAM-1.1.5/modules/pam_unix/pam_unix.8.xml
@@ -80,6 +80,13 @@
     </para>
 
     <para>
+      The maximum length of a password supported by the pam_unix module
+      via the helper binary is <emphasis>PAM_MAX_RESP_SIZE</emphasis>
+      - currently 512 bytes. The rest of the password provided by the
+      conversation function to the module will be ignored.
+    </para>
+
+    <para>
       The password component of this module performs the task of updating
       the user's password.
     </para>
Index: Linux-PAM-1.1.5/modules/pam_unix/pam_unix_passwd.c
===================================================================
--- Linux-PAM-1.1.5.orig/modules/pam_unix/pam_unix_passwd.c
+++ Linux-PAM-1.1.5/modules/pam_unix/pam_unix_passwd.c
@@ -237,15 +237,22 @@ static int _unix_run_update_binary(pam_h
 	/* wait for child */
 	/* if the stored password is NULL */
         int rc=0;
-	if (fromwhat)
-	  pam_modutil_write(fds[1], fromwhat, strlen(fromwhat)+1);
-	else
-	  pam_modutil_write(fds[1], "", 1);
-	if (towhat) {
-	  pam_modutil_write(fds[1], towhat, strlen(towhat)+1);
+	if (fromwhat) {
+	    int len = strlen(fromwhat);
+
+	    if (len > PAM_MAX_RESP_SIZE)
+	      len = PAM_MAX_RESP_SIZE;
+	    pam_modutil_write(fds[1], fromwhat, len);
 	}
-	else
-	  pam_modutil_write(fds[1], "", 1);
+        pam_modutil_write(fds[1], "", 1);
+	if (towhat) {
+	    int len = strlen(towhat);
+
+	    if (len > PAM_MAX_RESP_SIZE)
+	      len = PAM_MAX_RESP_SIZE;
+	    pam_modutil_write(fds[1], towhat, len);
+        }
+        pam_modutil_write(fds[1], "", 1);
 
 	close(fds[0]);       /* close here to avoid possible SIGPIPE above */
 	close(fds[1]);
Index: Linux-PAM-1.1.5/modules/pam_unix/passverify.c
===================================================================
--- Linux-PAM-1.1.5.orig/modules/pam_unix/passverify.c
+++ Linux-PAM-1.1.5/modules/pam_unix/passverify.c
@@ -1082,12 +1082,15 @@ getuidname(uid_t uid)
 int
 read_passwords(int fd, int npass, char **passwords)
 {
+        /* The passwords array must contain npass preallocated
+         * buffers of length MAXPASS + 1
+         */
         int rbytes = 0;
         int offset = 0;
         int i = 0;
         char *pptr;
         while (npass > 0) {
-                rbytes = read(fd, passwords[i]+offset, MAXPASS-offset);
+                rbytes = read(fd, passwords[i]+offset, MAXPASS+1-offset);
 
                 if (rbytes < 0) {
                         if (errno == EINTR) continue;
Index: Linux-PAM-1.1.5/modules/pam_unix/passverify.h
===================================================================
--- Linux-PAM-1.1.5.orig/modules/pam_unix/passverify.h
+++ Linux-PAM-1.1.5/modules/pam_unix/passverify.h
@@ -8,7 +8,7 @@
 
 #define PAM_UNIX_RUN_HELPER PAM_CRED_INSUFFICIENT
 
-#define MAXPASS		200	/* the maximum length of a password */
+#define MAXPASS PAM_MAX_RESP_SIZE  /* the maximum length of a password */
 
 #define OLD_PASSWORDS_FILE      "/etc/security/opasswd"
 
Index: Linux-PAM-1.1.5/modules/pam_unix/support.c
===================================================================
--- Linux-PAM-1.1.5.orig/modules/pam_unix/support.c
+++ Linux-PAM-1.1.5/modules/pam_unix/support.c
@@ -504,7 +504,12 @@ static int _unix_run_helper_binary(pam_h
 	/* if the stored password is NULL */
         int rc=0;
 	if (passwd != NULL) {            /* send the password to the child */
-	    if (write(fds[1], passwd, strlen(passwd)+1) == -1) {
+	    int len = strlen(passwd);
+
+	    if (len > PAM_MAX_RESP_SIZE)
+	      len = PAM_MAX_RESP_SIZE;
+	    if (write(fds[1], passwd, len) == -1 ||
+	        write(fds[1], "", 1) == -1) {
 	      pam_syslog (pamh, LOG_ERR, "Cannot send password to helper: %m");
 	      retval = PAM_AUTH_ERR;
 	    }
