b76250c
diff -up shadow-4.8/lib/defines.h.long-entry shadow-4.8/lib/defines.h
b76250c
--- shadow-4.8/lib/defines.h.long-entry	2020-01-13 10:29:45.288957339 +0100
b76250c
+++ shadow-4.8/lib/defines.h	2020-01-13 10:30:47.482902954 +0100
b76250c
@@ -388,6 +388,9 @@ extern char *strerror ();
4cb5077
 # endif
4cb5077
 #endif
4cb5077
 
4cb5077
+/* Maximum length of passwd entry */
4cb5077
+#define PASSWD_ENTRY_MAX_LENGTH 32768
4cb5077
+
b76250c
 #ifdef HAVE_SECURE_GETENV
b76250c
 #  define shadow_getenv(name) secure_getenv(name)
b76250c
 # else
b76250c
diff -up shadow-4.8/lib/pwio.c.long-entry shadow-4.8/lib/pwio.c
b76250c
--- shadow-4.8/lib/pwio.c.long-entry	2019-07-23 17:26:08.000000000 +0200
b76250c
+++ shadow-4.8/lib/pwio.c	2020-01-13 10:29:45.288957339 +0100
4cb5077
@@ -79,7 +79,10 @@ static int passwd_put (const void *ent,
4cb5077
 	    || (pw->pw_gid == (gid_t)-1)
4cb5077
 	    || (valid_field (pw->pw_gecos, ":\n") == -1)
4cb5077
 	    || (valid_field (pw->pw_dir, ":\n") == -1)
4cb5077
-	    || (valid_field (pw->pw_shell, ":\n") == -1)) {
4cb5077
+	    || (valid_field (pw->pw_shell, ":\n") == -1)
4cb5077
+	    || (strlen (pw->pw_name) + strlen (pw->pw_passwd) +
4cb5077
+	        strlen (pw->pw_gecos) + strlen (pw->pw_dir) +
4cb5077
+	        strlen (pw->pw_shell) + 100 > PASSWD_ENTRY_MAX_LENGTH)) {
4cb5077
 		return -1;
4cb5077
 	}
4cb5077
 
b76250c
diff -up shadow-4.8/lib/sgetpwent.c.long-entry shadow-4.8/lib/sgetpwent.c
b76250c
--- shadow-4.8/lib/sgetpwent.c.long-entry	2019-10-05 03:23:58.000000000 +0200
b76250c
+++ shadow-4.8/lib/sgetpwent.c	2020-01-13 10:29:45.288957339 +0100
4cb5077
@@ -57,7 +57,7 @@
4cb5077
 struct passwd *sgetpwent (const char *buf)
4cb5077
 {
4cb5077
 	static struct passwd pwent;
4cb5077
-	static char pwdbuf[1024];
4cb5077
+	static char pwdbuf[PASSWD_ENTRY_MAX_LENGTH];
4cb5077
 	register int i;
4cb5077
 	register char *cp;
4cb5077
 	char *fields[NFIELDS];
4cb5077
@@ -67,8 +67,10 @@ struct passwd *sgetpwent (const char *bu
4cb5077
 	 * the password structure remain valid.
4cb5077
 	 */
4cb5077
 
4cb5077
-	if (strlen (buf) >= sizeof pwdbuf)
4cb5077
+	if (strlen (buf) >= sizeof pwdbuf) {
4cb5077
+		fprintf (stderr, "Too long passwd entry encountered, file corruption?\n");
4cb5077
 		return 0;	/* fail if too long */
4cb5077
+	}
4cb5077
 	strcpy (pwdbuf, buf);
4cb5077
 
4cb5077
 	/*
b76250c
diff -up shadow-4.8/lib/sgetspent.c.long-entry shadow-4.8/lib/sgetspent.c
b76250c
--- shadow-4.8/lib/sgetspent.c.long-entry	2019-07-23 17:26:08.000000000 +0200
b76250c
+++ shadow-4.8/lib/sgetspent.c	2020-01-13 10:29:45.289957322 +0100
4cb5077
@@ -48,7 +48,7 @@
4cb5077
  */
4cb5077
 struct spwd *sgetspent (const char *string)
4cb5077
 {
4cb5077
-	static char spwbuf[1024];
4cb5077
+	static char spwbuf[PASSWD_ENTRY_MAX_LENGTH];
4cb5077
 	static struct spwd spwd;
4cb5077
 	char *fields[FIELDS];
4cb5077
 	char *cp;
4cb5077
@@ -61,6 +61,7 @@ struct spwd *sgetspent (const char *stri
4cb5077
 	 */
4cb5077
 
4cb5077
 	if (strlen (string) >= sizeof spwbuf) {
4cb5077
+		fprintf (stderr, "Too long shadow entry encountered, file corruption?\n");
4cb5077
 		return 0;	/* fail if too long */
4cb5077
 	}
4cb5077
 	strcpy (spwbuf, string);
b76250c
diff -up shadow-4.8/lib/shadowio.c.long-entry shadow-4.8/lib/shadowio.c
b76250c
--- shadow-4.8/lib/shadowio.c.long-entry	2019-07-23 17:26:08.000000000 +0200
b76250c
+++ shadow-4.8/lib/shadowio.c	2020-01-13 10:29:45.289957322 +0100
4cb5077
@@ -79,7 +79,9 @@ static int shadow_put (const void *ent,
4cb5077
 
4cb5077
 	if (   (NULL == sp)
4cb5077
 	    || (valid_field (sp->sp_namp, ":\n") == -1)
4cb5077
-	    || (valid_field (sp->sp_pwdp, ":\n") == -1)) {
4cb5077
+	    || (valid_field (sp->sp_pwdp, ":\n") == -1)
4cb5077
+	    || (strlen (sp->sp_namp) + strlen (sp->sp_pwdp) +
4cb5077
+	        1000 > PASSWD_ENTRY_MAX_LENGTH)) {
4cb5077
 		return -1;
4cb5077
 	}
4cb5077