Project

General

Profile

Backport #3235 ยป ruby_envspace.patch

Bugfix for environment-space scanner to only copy/move contiguous environment-variables. - rubyjedi (Laurence Lee), 05/29/2010 06:05 PM

View differences:

ruby-1.8.8-head/ruby.c (working copy)
1051 1051
get_arglen(int argc, char **argv)
1052 1052
{
1053 1053
    char *s = argv[0];
1054
    int i;
1054
    int i, j;
1055 1055

  
1056 1056
    if (!argc) return 0;
1057 1057
    s += strlen(s);
......
1066 1066
	}
1067 1067
    }
1068 1068
#if defined(USE_ENVSPACE_FOR_ARG0)
1069
    if (environ && (s+1 == environ[0])) {
1070
	s++;
1071
	s += strlen(s);
1072
	for (i = 1; environ[i]; i++) {
1073
	    if (environ[i] == s + 1) {
1069
    if (environ) {
1070
	for (i = 0; environ[i] == s+1; i++) {
1074 1071
		s++;
1075 1072
		s += strlen(s);	/* this one is ok too */
1076
	    }
1077 1073
	}
1078 1074
# if defined(HAVE_SETENV) && defined(HAVE_UNSETENV)
1079 1075
	{
1080 1076
	    char *t = malloc(s - environ[0] + 1);
1081
	    for (i = 0; environ[i]; i++) {
1082
		size_t len = strlen(environ[i]) + 1;
1083
		memcpy(t, environ[i], len);
1084
		environ[i] = t;
1077
	    for (j = 0; j<i && environ[j]; j++) {
1078
		size_t len = strlen(environ[j]) + 1;
1079
		memcpy(t, environ[j], len);
1080
		environ[j] = t;
1085 1081
		t += len;
1086 1082
	    }
1087 1083
	}