Blame SOURCES/shadow-4.5-long-entry.patch

e5cfd7
diff -up shadow-4.5/lib/defines.h.long-entry shadow-4.5/lib/defines.h
e5cfd7
--- shadow-4.5/lib/defines.h.long-entry	2014-09-01 16:36:40.000000000 +0200
e5cfd7
+++ shadow-4.5/lib/defines.h	2018-04-20 11:53:07.419308212 +0200
e5cfd7
@@ -382,4 +382,7 @@ extern char *strerror ();
e5cfd7
 # endif
e5cfd7
 #endif
e5cfd7
 
e5cfd7
+/* Maximum length of passwd entry */
e5cfd7
+#define PASSWD_ENTRY_MAX_LENGTH 32768
e5cfd7
+
e5cfd7
 #endif				/* _DEFINES_H_ */
e5cfd7
diff -up shadow-4.5/lib/pwio.c.long-entry shadow-4.5/lib/pwio.c
e5cfd7
--- shadow-4.5/lib/pwio.c.long-entry	2015-11-17 17:45:15.000000000 +0100
e5cfd7
+++ shadow-4.5/lib/pwio.c	2018-04-20 12:10:24.400837235 +0200
e5cfd7
@@ -79,7 +79,10 @@ static int passwd_put (const void *ent,
e5cfd7
 	    || (pw->pw_gid == (gid_t)-1)
e5cfd7
 	    || (valid_field (pw->pw_gecos, ":\n") == -1)
e5cfd7
 	    || (valid_field (pw->pw_dir, ":\n") == -1)
e5cfd7
-	    || (valid_field (pw->pw_shell, ":\n") == -1)) {
e5cfd7
+	    || (valid_field (pw->pw_shell, ":\n") == -1)
e5cfd7
+	    || (strlen (pw->pw_name) + strlen (pw->pw_passwd) +
e5cfd7
+	        strlen (pw->pw_gecos) + strlen (pw->pw_dir) +
e5cfd7
+	        strlen (pw->pw_shell) + 100 > PASSWD_ENTRY_MAX_LENGTH)) {
e5cfd7
 		return -1;
e5cfd7
 	}
e5cfd7
 
e5cfd7
diff -up shadow-4.5/lib/sgetpwent.c.long-entry shadow-4.5/lib/sgetpwent.c
e5cfd7
--- shadow-4.5/lib/sgetpwent.c.long-entry	2014-09-01 16:36:40.000000000 +0200
e5cfd7
+++ shadow-4.5/lib/sgetpwent.c	2018-04-20 12:16:31.911513808 +0200
e5cfd7
@@ -57,7 +57,7 @@
e5cfd7
 struct passwd *sgetpwent (const char *buf)
e5cfd7
 {
e5cfd7
 	static struct passwd pwent;
e5cfd7
-	static char pwdbuf[1024];
e5cfd7
+	static char pwdbuf[PASSWD_ENTRY_MAX_LENGTH];
e5cfd7
 	register int i;
e5cfd7
 	register char *cp;
e5cfd7
 	char *fields[NFIELDS];
e5cfd7
@@ -67,8 +67,10 @@ struct passwd *sgetpwent (const char *bu
e5cfd7
 	 * the password structure remain valid.
e5cfd7
 	 */
e5cfd7
 
e5cfd7
-	if (strlen (buf) >= sizeof pwdbuf)
e5cfd7
+	if (strlen (buf) >= sizeof pwdbuf) {
e5cfd7
+		fprintf (stderr, "Too long passwd entry encountered, file corruption?\n");
e5cfd7
 		return 0;	/* fail if too long */
e5cfd7
+	}
e5cfd7
 	strcpy (pwdbuf, buf);
e5cfd7
 
e5cfd7
 	/*
e5cfd7
diff -up shadow-4.5/lib/sgetspent.c.long-entry shadow-4.5/lib/sgetspent.c
e5cfd7
--- shadow-4.5/lib/sgetspent.c.long-entry	2014-09-01 16:36:40.000000000 +0200
e5cfd7
+++ shadow-4.5/lib/sgetspent.c	2018-04-20 12:16:54.505056257 +0200
e5cfd7
@@ -48,7 +48,7 @@
e5cfd7
  */
e5cfd7
 struct spwd *sgetspent (const char *string)
e5cfd7
 {
e5cfd7
-	static char spwbuf[1024];
e5cfd7
+	static char spwbuf[PASSWD_ENTRY_MAX_LENGTH];
e5cfd7
 	static struct spwd spwd;
e5cfd7
 	char *fields[FIELDS];
e5cfd7
 	char *cp;
e5cfd7
@@ -61,6 +61,7 @@ struct spwd *sgetspent (const char *stri
e5cfd7
 	 */
e5cfd7
 
e5cfd7
 	if (strlen (string) >= sizeof spwbuf) {
e5cfd7
+		fprintf (stderr, "Too long shadow entry encountered, file corruption?\n");
e5cfd7
 		return 0;	/* fail if too long */
e5cfd7
 	}
e5cfd7
 	strcpy (spwbuf, string);
e5cfd7
diff -up shadow-4.5/lib/shadowio.c.long-entry shadow-4.5/lib/shadowio.c
e5cfd7
--- shadow-4.5/lib/shadowio.c.long-entry	2016-12-07 06:30:41.000000001 +0100
e5cfd7
+++ shadow-4.5/lib/shadowio.c	2018-04-20 12:12:03.292171667 +0200
e5cfd7
@@ -79,7 +79,9 @@ static int shadow_put (const void *ent,
e5cfd7
 
e5cfd7
 	if (   (NULL == sp)
e5cfd7
 	    || (valid_field (sp->sp_namp, ":\n") == -1)
e5cfd7
-	    || (valid_field (sp->sp_pwdp, ":\n") == -1)) {
e5cfd7
+	    || (valid_field (sp->sp_pwdp, ":\n") == -1)
e5cfd7
+	    || (strlen (sp->sp_namp) + strlen (sp->sp_pwdp) +
e5cfd7
+	        1000 > PASSWD_ENTRY_MAX_LENGTH)) {
e5cfd7
 		return -1;
e5cfd7
 	}
e5cfd7