09299d
diff -rup netkit-ftp-0.17/ftp/ruserpass.c netkit-ftp-0.17-new/ftp/ruserpass.c
09299d
--- netkit-ftp-0.17/ftp/ruserpass.c	2012-10-29 15:11:10.593841089 +0100
09299d
+++ netkit-ftp-0.17-new/ftp/ruserpass.c	2012-10-29 15:13:14.379822697 +0100
09299d
@@ -58,7 +58,8 @@ static int token(void);
09299d
 #define	ID	10
09299d
 #define	MACH	11
09299d
 
09299d
-static char tokval[100];
09299d
+#define MAXTOKENLEN 4096
09299d
+static char tokval[MAXTOKENLEN];
09299d
 
09299d
 static struct toktab {
09299d
 	const char *tokstr;
09299d
@@ -249,13 +250,16 @@ bad:
09299d
 	return(-1);
09299d
 }
09299d
 
09299d
-static 
09299d
+static
09299d
 int
09299d
 token(void)
09299d
 {
09299d
 	char *cp;
09299d
 	int c;
09299d
 	struct toktab *t;
09299d
+	size_t toklen = 0;
09299d
+	int showwarn = 1;
09299d
+	int quote = 0;
09299d
 
09299d
 	if (feof(cfile))
09299d
 		return (0);
09299d
@@ -266,20 +270,32 @@ token(void)
09299d
 		return (0);
09299d
 	cp = tokval;
09299d
 	if (c == '"') {
09299d
-		while ((c = getc(cfile)) != EOF && c != '"') {
09299d
-			if (c == '\\')
09299d
-				c = getc(cfile);
09299d
-			*cp++ = c;
09299d
-		}
09299d
-	} else {
09299d
+		quote = 1;
09299d
+	}
09299d
+	else {
09299d
 		*cp++ = c;
09299d
-		while ((c = getc(cfile)) != EOF
09299d
-		    && c != '\n' && c != '\t' && c != ' ' && c != ',') {
09299d
-			if (c == '\\')
09299d
-				c = getc(cfile);
09299d
-			*cp++ = c;
09299d
+		toklen++;
09299d
+	}
09299d
+	while ((c = getc(cfile)) != EOF) {
09299d
+		if (c == '"')
09299d
+			break;
09299d
+		if (c == '\\')
09299d
+			c = getc(cfile);
09299d
+		if (!quote && (c == '\n' || c == '\t' || c == ' ' || c == ','))
09299d
+			break;
09299d
+		if (toklen >= MAXTOKENLEN) {
09299d
+			if (showwarn) {
09299d
+				fprintf(stderr,
09299d
+						"Warning: .netrc token too long, will be trunctated to %zd characters\n",
09299d
+						toklen);
09299d
+				showwarn = 0;
09299d
+			}
09299d
+			continue;
09299d
 		}
09299d
+		*cp++ = c;
09299d
+		toklen++;
09299d
 	}
09299d
+
09299d
 	*cp = 0;
09299d
 	if (tokval[0] == 0)
09299d
 		return (0);