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

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