changeset 1834:94dc11094e26

Increase max window size to 10MB, fallback rather than exiting if an invalid value is given.
author Matt Johnston <matt@codeconstruct.com.au>
date Tue, 12 Oct 2021 23:32:10 +0800
parents 870f6e386a0b
children 90ac15aeac43
files cli-runopts.c common-runopts.c runopts.h svr-runopts.c sysoptions.h
diffstat 5 files changed, 25 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/cli-runopts.c	Tue Oct 12 23:31:09 2021 +0800
+++ b/cli-runopts.c	Tue Oct 12 23:32:10 2021 +0800
@@ -79,7 +79,7 @@
 #if DROPBEAR_CLI_REMOTETCPFWD
 					"-R <[listenaddress:]listenport:remotehost:remoteport> Remote port forwarding\n"
 #endif
-					"-W <receive_window_buffer> (default %d, larger may be faster, max 1MB)\n"
+					"-W <receive_window_buffer> (default %d, larger may be faster, max 10MB)\n"
 					"-K <keepalive>  (0 is never, default %d)\n"
 					"-I <idle_timeout>  (0 is never, default %d)\n"
 #if DROPBEAR_CLI_NETCAT
@@ -451,12 +451,9 @@
 			&& cli_opts.no_cmd == 0) {
 		dropbear_exit("Command required for -f");
 	}
-	
+
 	if (recv_window_arg) {
-		opts.recv_window = atol(recv_window_arg);
-		if (opts.recv_window == 0 || opts.recv_window > MAX_RECV_WINDOW) {
-			dropbear_exit("Bad recv window '%s'", recv_window_arg);
-		}
+		parse_recv_window(recv_window_arg);
 	}
 	if (keepalive_arg) {
 		unsigned int val;
--- a/common-runopts.c	Tue Oct 12 23:31:09 2021 +0800
+++ b/common-runopts.c	Tue Oct 12 23:32:10 2021 +0800
@@ -101,4 +101,20 @@
 	fprintf(stderr, "Dropbear v%s\n", DROPBEAR_VERSION);
 }
 
+void parse_recv_window(const char* recv_window_arg) {
+	int ret;
+	unsigned int rw;
 
+	ret = m_str_to_uint(recv_window_arg, &rw);
+	if (ret == DROPBEAR_FAILURE || rw == 0 || rw > MAX_RECV_WINDOW) {
+		if (rw > MAX_RECV_WINDOW) {
+			opts.recv_window = MAX_RECV_WINDOW;
+		}
+		dropbear_log(LOG_WARNING, "Bad recv window '%s', using %d",
+			recv_window_arg, opts.recv_window);
+	} else {
+		opts.recv_window = rw;
+	}
+
+}
+
--- a/runopts.h	Tue Oct 12 23:31:09 2021 +0800
+++ b/runopts.h	Tue Oct 12 23:32:10 2021 +0800
@@ -195,5 +195,6 @@
 #endif
 
 void print_version(void);
+void parse_recv_window(const char* recv_window_arg);
 
 #endif /* DROPBEAR_RUNOPTS_H_ */
--- a/svr-runopts.c	Tue Oct 12 23:31:09 2021 +0800
+++ b/svr-runopts.c	Tue Oct 12 23:32:10 2021 +0800
@@ -100,7 +100,7 @@
 #if INETD_MODE
 					"-i		Start for inetd\n"
 #endif
-					"-W <receive_window_buffer> (default %d, larger may be faster, max 1MB)\n"
+					"-W <receive_window_buffer> (default %d, larger may be faster, max 10MB)\n"
 					"-K <keepalive>  (0 is never, default %d, in seconds)\n"
 					"-I <idle_timeout>  (0 is never, default %d, in seconds)\n"
 #if DROPBEAR_PLUGIN
@@ -385,12 +385,9 @@
 		}
 	}
 #endif
-	
+
 	if (recv_window_arg) {
-		opts.recv_window = atol(recv_window_arg);
-		if (opts.recv_window == 0 || opts.recv_window > MAX_RECV_WINDOW) {
-			dropbear_exit("Bad recv window '%s'", recv_window_arg);
-		}
+		parse_recv_window(recv_window_arg);
 	}
 
 	if (maxauthtries_arg) {
@@ -402,7 +399,7 @@
 		svr_opts.maxauthtries = val;
 	}
 
-	
+
 	if (keepalive_arg) {
 		unsigned int val;
 		if (m_str_to_uint(keepalive_arg, &val) == DROPBEAR_FAILURE) {
--- a/sysoptions.h	Tue Oct 12 23:31:09 2021 +0800
+++ b/sysoptions.h	Tue Oct 12 23:32:10 2021 +0800
@@ -196,7 +196,7 @@
 
 #define RECV_WINDOWEXTEND (opts.recv_window / 3) /* We send a "window extend" every
 								RECV_WINDOWEXTEND bytes */
-#define MAX_RECV_WINDOW (1024*1024) /* 1 MB should be enough */
+#define MAX_RECV_WINDOW (10*1024*1024) /* 10 MB should be enough */
 
 #define MAX_CHANNELS 1000 /* simple mem restriction, includes each tcp/x11
 							connection, so can't be _too_ small */