Module Name:    src
Committed By:   christos
Date:           Sun Feb 18 22:29:56 UTC 2024

Modified Files:
        src/usr.bin/ftp: fetch.c ftp.1 ftp.c ftp_var.h main.c ssl.c

Log Message:
Add -b <buflen> to specify the buffer size.


To generate a diff of this commit:
cvs rdiff -u -r1.238 -r1.239 src/usr.bin/ftp/fetch.c
cvs rdiff -u -r1.151 -r1.152 src/usr.bin/ftp/ftp.1
cvs rdiff -u -r1.175 -r1.176 src/usr.bin/ftp/ftp.c
cvs rdiff -u -r1.86 -r1.87 src/usr.bin/ftp/ftp_var.h
cvs rdiff -u -r1.129 -r1.130 src/usr.bin/ftp/main.c
cvs rdiff -u -r1.16 -r1.17 src/usr.bin/ftp/ssl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/ftp/fetch.c
diff -u src/usr.bin/ftp/fetch.c:1.238 src/usr.bin/ftp/fetch.c:1.239
--- src/usr.bin/ftp/fetch.c:1.238	Sat Aug 12 03:40:13 2023
+++ src/usr.bin/ftp/fetch.c	Sun Feb 18 17:29:56 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: fetch.c,v 1.238 2023/08/12 07:40:13 mlelstv Exp $	*/
+/*	$NetBSD: fetch.c,v 1.239 2024/02/18 22:29:56 christos Exp $	*/
 
 /*-
  * Copyright (c) 1997-2015 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: fetch.c,v 1.238 2023/08/12 07:40:13 mlelstv Exp $");
+__RCSID("$NetBSD: fetch.c,v 1.239 2024/02/18 22:29:56 christos Exp $");
 #endif /* not lint */
 
 /*
@@ -1116,15 +1116,17 @@ negotiate_connection(FETCH *fin, const c
     char **auth, struct urlinfo *ui)
 {
 	int			len, hcode, rv;
-	char			buf[FTPBUFLEN], *ep;
+	char			*buf = NULL, *ep;
 	const char		*cp, *token;
 	char			*location, *message;
 
 	*auth = message = location = NULL;
 
+	buf = ftp_malloc(ftp_buflen);
+
 	/* Read the response */
 	ep = buf;
-	switch (getresponse(fin, &ep, sizeof(buf), &hcode)) {
+	switch (getresponse(fin, &ep, ftp_buflen, &hcode)) {
 	case C_CLEANUP:
 		goto cleanup_fetch_url;
 	case C_IMPROPER:
@@ -1137,7 +1139,7 @@ negotiate_connection(FETCH *fin, const c
 	/* Read the rest of the header. */
 
 	for (;;) {
-		if ((rv = getresponseline(fin, buf, sizeof(buf), &len)) != C_OK)
+		if ((rv = getresponseline(fin, buf, ftp_buflen, &len)) != C_OK)
 			goto cleanup_fetch_url;
 		if (len == 0)
 			break;
@@ -1265,6 +1267,7 @@ improper:
 	rv = C_IMPROPER;
 	goto out;
 out:
+	FREEPTR(buf);
 	FREEPTR(message);
 	FREEPTR(location);
 	return rv;
@@ -1279,7 +1282,7 @@ connectmethod(FETCH *fin, const char *ur
 	void *ssl;
 	int hcode, rv;
 	const char *cp;
-	char buf[FTPBUFLEN], *ep;
+	char *buf = NULL, *ep;
 	char *message = NULL;
 
 	print_connect(fin, oui);
@@ -1299,9 +1302,11 @@ connectmethod(FETCH *fin, const char *ur
 	}
 	alarmtimer(0);
 
+	buf = ftp_malloc(ftp_buflen);
+
 	/* Read the response */
 	ep = buf;
-	switch (getresponse(fin, &ep, sizeof(buf), &hcode)) {
+	switch (getresponse(fin, &ep, ftp_buflen, &hcode)) {
 	case C_CLEANUP:
 		goto cleanup_fetch_url;
 	case C_IMPROPER:
@@ -1313,7 +1318,7 @@ connectmethod(FETCH *fin, const char *ur
 
 	for (;;) {
 		int len;
-		if (getresponseline(fin, buf, sizeof(buf), &len) != C_OK)
+		if (getresponseline(fin, buf, ftp_buflen, &len) != C_OK)
 			goto cleanup_fetch_url;
 		if (len == 0)
 			break;
@@ -1364,6 +1369,7 @@ cleanup_fetch_url:
 	rv = C_CLEANUP;
 	goto out;
 out:
+	FREEPTR(buf);
 	FREEPTR(message);
 	return rv;
 }

Index: src/usr.bin/ftp/ftp.1
diff -u src/usr.bin/ftp/ftp.1:1.151 src/usr.bin/ftp/ftp.1:1.152
--- src/usr.bin/ftp/ftp.1:1.151	Fri Dec  8 21:15:11 2023
+++ src/usr.bin/ftp/ftp.1	Sun Feb 18 17:29:56 2024
@@ -1,4 +1,4 @@
-.\" 	$NetBSD: ftp.1,v 1.151 2023/12/09 02:15:11 lukem Exp $
+.\" 	$NetBSD: ftp.1,v 1.152 2024/02/18 22:29:56 christos Exp $
 .\"
 .\" Copyright (c) 1996-2023 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -57,7 +57,7 @@
 .\"
 .\"	@(#)ftp.1	8.3 (Berkeley) 10/9/94
 .\"
-.Dd December 9, 2023
+.Dd February 18, 2024
 .Dt FTP 1
 .Os
 .Sh NAME
@@ -69,6 +69,7 @@
 .Op Fl N Ar netrc
 .Op Fl o Ar output
 .Op Fl P Ar port
+.Op Fl b Ar bufsize
 .Op Fl q Ar quittime
 .Op Fl r Ar retry
 .Op Fl s Ar srcaddr
@@ -201,6 +202,9 @@ implement passive mode properly.
 Causes
 .Nm
 to bypass normal login procedure, and use an anonymous login instead.
+.It Fl b Ar bufsize
+Change the input buffer size to
+.Ar bufsize .
 .It Fl d
 Enables debugging.
 .It Fl e

Index: src/usr.bin/ftp/ftp.c
diff -u src/usr.bin/ftp/ftp.c:1.175 src/usr.bin/ftp/ftp.c:1.176
--- src/usr.bin/ftp/ftp.c:1.175	Fri May  5 11:46:06 2023
+++ src/usr.bin/ftp/ftp.c	Sun Feb 18 17:29:56 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: ftp.c,v 1.175 2023/05/05 15:46:06 lukem Exp $	*/
+/*	$NetBSD: ftp.c,v 1.176 2024/02/18 22:29:56 christos Exp $	*/
 
 /*-
  * Copyright (c) 1996-2021 The NetBSD Foundation, Inc.
@@ -92,7 +92,7 @@
 #if 0
 static char sccsid[] = "@(#)ftp.c	8.6 (Berkeley) 10/27/94";
 #else
-__RCSID("$NetBSD: ftp.c,v 1.175 2023/05/05 15:46:06 lukem Exp $");
+__RCSID("$NetBSD: ftp.c,v 1.176 2024/02/18 22:29:56 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -130,6 +130,7 @@ sigjmp_buf	ptabort;
 int	ptabflg;
 int	ptflag = 0;
 char	pasv[BUFSIZ];	/* passive port for proxy data connection */
+size_t	ftp_buflen = FTPBUFLEN;
 
 static int empty(FILE *, FILE *, int);
 __dead static void abort_squared(int);

Index: src/usr.bin/ftp/ftp_var.h
diff -u src/usr.bin/ftp/ftp_var.h:1.86 src/usr.bin/ftp/ftp_var.h:1.87
--- src/usr.bin/ftp/ftp_var.h:1.86	Fri Sep 10 17:52:17 2021
+++ src/usr.bin/ftp/ftp_var.h	Sun Feb 18 17:29:56 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: ftp_var.h,v 1.86 2021/09/10 21:52:17 rillig Exp $	*/
+/*	$NetBSD: ftp_var.h,v 1.87 2024/02/18 22:29:56 christos Exp $	*/
 
 /*-
  * Copyright (c) 1996-2009 The NetBSD Foundation, Inc.
@@ -323,6 +323,7 @@ GLOBAL	int	 data;
 extern	struct cmd	cmdtab[];
 extern	struct option	optiontab[];
 
+extern	size_t ftp_buflen;
 
 #define	EMPTYSTRING(x)	((x) == NULL || (*(x) == '\0'))
 #define	FREEPTR(x)	if ((x) != NULL) { free(x); (x) = NULL; }

Index: src/usr.bin/ftp/main.c
diff -u src/usr.bin/ftp/main.c:1.129 src/usr.bin/ftp/main.c:1.130
--- src/usr.bin/ftp/main.c:1.129	Sat Feb 25 07:07:25 2023
+++ src/usr.bin/ftp/main.c	Sun Feb 18 17:29:56 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.129 2023/02/25 12:07:25 mlelstv Exp $	*/
+/*	$NetBSD: main.c,v 1.130 2024/02/18 22:29:56 christos Exp $	*/
 
 /*-
  * Copyright (c) 1996-2023 The NetBSD Foundation, Inc.
@@ -98,7 +98,7 @@ __COPYRIGHT("@(#) Copyright (c) 1985, 19
 #if 0
 static char sccsid[] = "@(#)main.c	8.6 (Berkeley) 10/9/94";
 #else
-__RCSID("$NetBSD: main.c,v 1.129 2023/02/25 12:07:25 mlelstv Exp $");
+__RCSID("$NetBSD: main.c,v 1.130 2024/02/18 22:29:56 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -267,7 +267,7 @@ main(int volatile argc, char **volatile 
 		}
 	}
 
-	while ((ch = getopt(argc, argv, ":46AadefginN:o:pP:q:r:Rs:tT:u:vVx:")) != -1) {
+	while ((ch = getopt(argc, argv, ":46Aab:defginN:o:pP:q:r:Rs:tT:u:vVx:")) != -1) {
 		switch (ch) {
 		case '4':
 			family = AF_INET;
@@ -290,6 +290,12 @@ main(int volatile argc, char **volatile 
 			anonftp = 1;
 			break;
 
+		case 'b':
+			ftp_buflen = strtol(optarg, &ep, 0);
+			if (ftp_buflen < 1 || *ep != '\0')
+				errx(1, "Bad buflen value: %s", optarg);
+			break;
+
 		case 'd':
 			options |= SO_DEBUG;
 			ftp_debug++;
@@ -1089,6 +1095,7 @@ usage_help(void)
 "  -6            Only use IPv6 addresses\n"
 "  -A            Force active mode\n"
 "  -a            Use anonymous login\n"
+"  -b BUFLEN     Use BUFLEN bytes for fetch buffer\n"
 "  -d            Enable debugging\n"
 "  -e            Disable command-line editing\n"
 "  -f            Force cache reload for FTP or HTTP proxy transfers\n"

Index: src/usr.bin/ftp/ssl.c
diff -u src/usr.bin/ftp/ssl.c:1.16 src/usr.bin/ftp/ssl.c:1.17
--- src/usr.bin/ftp/ssl.c:1.16	Tue May 16 14:52:09 2023
+++ src/usr.bin/ftp/ssl.c	Sun Feb 18 17:29:56 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: ssl.c,v 1.16 2023/05/16 18:52:09 christos Exp $	*/
+/*	$NetBSD: ssl.c,v 1.17 2024/02/18 22:29:56 christos Exp $	*/
 
 /*-
  * Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav
@@ -35,7 +35,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: ssl.c,v 1.16 2023/05/16 18:52:09 christos Exp $");
+__RCSID("$NetBSD: ssl.c,v 1.17 2024/02/18 22:29:56 christos Exp $");
 #endif
 
 #include <err.h>
@@ -579,7 +579,7 @@ fetch_getline(struct fetch_connect *conn
 				break;
 		}
 		if (errormsg)
-			*errormsg = "Input line is too long";
+			*errormsg = "Input line is too long (specify -b > 4K)";
 		fetch_clearerr(conn);
 		return -3;
 	}

Reply via email to