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

57b0e3
diff -up shadow-4.1.5.1/lib/defines.h.long-entry shadow-4.1.5.1/lib/defines.h
57b0e3
--- shadow-4.1.5.1/lib/defines.h.long-entry	2011-09-18 22:44:10.000000000 +0200
57b0e3
+++ shadow-4.1.5.1/lib/defines.h	2018-04-24 16:34:31.261417493 +0200
57b0e3
@@ -382,4 +382,7 @@ extern char *strerror ();
57b0e3
 # endif
57b0e3
 #endif
57b0e3
 
57b0e3
+/* Maximum length of passwd entry */
57b0e3
+#define PASSWD_ENTRY_MAX_LENGTH 32768
57b0e3
+
57b0e3
 #endif				/* _DEFINES_H_ */
57b0e3
diff -up shadow-4.1.5.1/lib/pwio.c.long-entry shadow-4.1.5.1/lib/pwio.c
57b0e3
--- shadow-4.1.5.1/lib/pwio.c.long-entry	2011-02-16 21:32:24.000000000 +0100
57b0e3
+++ shadow-4.1.5.1/lib/pwio.c	2018-04-24 16:34:31.263417454 +0200
57b0e3
@@ -79,7 +79,10 @@ static int passwd_put (const void *ent,
57b0e3
 	    || (pw->pw_gid == (gid_t)-1)
57b0e3
 	    || (valid_field (pw->pw_gecos, ":\n") == -1)
57b0e3
 	    || (valid_field (pw->pw_dir, ":\n") == -1)
57b0e3
-	    || (valid_field (pw->pw_shell, ":\n") == -1)) {
57b0e3
+	    || (valid_field (pw->pw_shell, ":\n") == -1)
57b0e3
+	    || (strlen (pw->pw_name) + strlen (pw->pw_passwd) +
57b0e3
+	        strlen (pw->pw_gecos) + strlen (pw->pw_dir) +
57b0e3
+	        strlen (pw->pw_shell) + 100 > PASSWD_ENTRY_MAX_LENGTH)) {
57b0e3
 		return -1;
57b0e3
 	}
57b0e3
 
57b0e3
diff -up shadow-4.1.5.1/lib/sgetpwent.c.long-entry shadow-4.1.5.1/lib/sgetpwent.c
57b0e3
--- shadow-4.1.5.1/lib/sgetpwent.c.long-entry	2009-04-06 06:28:53.000000000 +0200
57b0e3
+++ shadow-4.1.5.1/lib/sgetpwent.c	2018-04-24 16:34:31.263417454 +0200
57b0e3
@@ -57,7 +57,7 @@
57b0e3
 struct passwd *sgetpwent (const char *buf)
57b0e3
 {
57b0e3
 	static struct passwd pwent;
57b0e3
-	static char pwdbuf[1024];
57b0e3
+	static char pwdbuf[PASSWD_ENTRY_MAX_LENGTH];
57b0e3
 	register int i;
57b0e3
 	register char *cp;
57b0e3
 	char *fields[NFIELDS];
57b0e3
@@ -67,8 +67,10 @@ struct passwd *sgetpwent (const char *bu
57b0e3
 	 * the password structure remain valid.
57b0e3
 	 */
57b0e3
 
57b0e3
-	if (strlen (buf) >= sizeof pwdbuf)
57b0e3
+	if (strlen (buf) >= sizeof pwdbuf) {
57b0e3
+		fprintf (stderr, "Too long passwd entry encountered, file corruption?\n");
57b0e3
 		return 0;	/* fail if too long */
57b0e3
+	}
57b0e3
 	strcpy (pwdbuf, buf);
57b0e3
 
57b0e3
 	/*
57b0e3
diff -up shadow-4.1.5.1/lib/sgetspent.c.long-entry shadow-4.1.5.1/lib/sgetspent.c
57b0e3
--- shadow-4.1.5.1/lib/sgetspent.c.long-entry	2009-04-12 04:46:43.000000000 +0200
57b0e3
+++ shadow-4.1.5.1/lib/sgetspent.c	2018-04-24 16:34:31.264417435 +0200
57b0e3
@@ -48,7 +48,7 @@
57b0e3
  */
57b0e3
 struct spwd *sgetspent (const char *string)
57b0e3
 {
57b0e3
-	static char spwbuf[1024];
57b0e3
+	static char spwbuf[PASSWD_ENTRY_MAX_LENGTH];
57b0e3
 	static struct spwd spwd;
57b0e3
 	char *fields[FIELDS];
57b0e3
 	char *cp;
57b0e3
@@ -61,6 +61,7 @@ struct spwd *sgetspent (const char *stri
57b0e3
 	 */
57b0e3
 
57b0e3
 	if (strlen (string) >= sizeof spwbuf) {
57b0e3
+		fprintf (stderr, "Too long shadow entry encountered, file corruption?\n");
57b0e3
 		return 0;	/* fail if too long */
57b0e3
 	}
57b0e3
 	strcpy (spwbuf, string);
57b0e3
diff -up shadow-4.1.5.1/lib/shadowio.c.long-entry shadow-4.1.5.1/lib/shadowio.c
57b0e3
--- shadow-4.1.5.1/lib/shadowio.c.long-entry	2011-02-16 21:32:24.000000000 +0100
57b0e3
+++ shadow-4.1.5.1/lib/shadowio.c	2018-04-24 16:34:31.265417416 +0200
57b0e3
@@ -78,7 +78,9 @@ static int shadow_put (const void *ent,
57b0e3
 
57b0e3
 	if (   (NULL == sp)
57b0e3
 	    || (valid_field (sp->sp_namp, ":\n") == -1)
57b0e3
-	    || (valid_field (sp->sp_pwdp, ":\n") == -1)) {
57b0e3
+	    || (valid_field (sp->sp_pwdp, ":\n") == -1)
57b0e3
+	    || (strlen (sp->sp_namp) + strlen (sp->sp_pwdp) +
57b0e3
+	        1000 > PASSWD_ENTRY_MAX_LENGTH)) {
57b0e3
 		return -1;
57b0e3
 	}
57b0e3