[PATCH]: Fix environment variable size restriction in Cygwin version

Corinna Vinschen vinschen at redhat.com
Wed Dec 19 06:25:26 EST 2001


Hi,

the following patch changes the Cygwin specific function copy_environment()
to not restricting the strlen of a single environment variable to 512 byte.

The PAM specific function do_pam_environment() (also in session.c) has
the same problem but I don't know if that's important for PAM since
only PAM specific environment variables are copied in that function.

The below patch fixes that problem only for Cygwin for now.

Thanks,
Corinna

Index: session.c
===================================================================
RCS file: /cvs/openssh_cvs/session.c,v
retrieving revision 1.158
diff -u -p -r1.158 session.c
--- session.c	7 Dec 2001 17:26:49 -0000	1.158
+++ session.c	18 Dec 2001 19:07:14 -0000
@@ -918,25 +918,29 @@ void do_pam_environment(char ***env, u_i
 #ifdef HAVE_CYGWIN
 void copy_environment(char ***env, u_int *envsize)
 {
-	char *equals, var_name[512], var_val[512];
+	char *var_name = NULL, *var_val;
+	size_t size = 0, i_size;
 	int i;
 
 	for(i = 0; environ[i] != NULL; i++) {
-		if ((equals = strstr(environ[i], "=")) == NULL)
+		if ((i_size = strlen(environ[i]) + 1) < 3)
 			continue;
 
-		if (strlen(environ[i]) < (sizeof(var_name) - 1)) {
-			memset(var_name, '\0', sizeof(var_name));
-			memset(var_val, '\0', sizeof(var_val));
-
-			strncpy(var_name, environ[i], equals - environ[i]);
-			strcpy(var_val, equals + 1);
+		if (i_size > size) {
+			var_name = xrealloc(var_name, i_size);
+		    	size = i_size;
+		}
+		strcpy(var_name, environ[i]);
+		if ((var_val = strchr(var_name, '=')) != NULL) {
+			*var_val++ = '\0';
 
 			debug3("Copy environment: %s=%s", var_name, var_val);
 
 			child_set_env(env, envsize, var_name, var_val);
 		}
 	}
+	if (var_name)
+		xfree(var_name);
 }
 #endif
 

-- 
Corinna Vinschen
Cygwin Developer
Red Hat, Inc.
mailto:vinschen at redhat.com



More information about the openssh-unix-dev mailing list