Skip to content

Fixing integer overflow bugs in Perl_my_setenv #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions util.c
Original file line number Diff line number Diff line change
Expand Up @@ -2080,7 +2080,7 @@ Perl_my_setenv(pTHX_ const char *nam, const char *val)
/* most putenv()s leak, so we manipulate environ directly */
I32 i;
const I32 len = strlen(nam);
int nlen, vlen;
size_t nlen, vlen;

/* where does it go? */
for (i = 0; environ[i]; i++) {
Expand All @@ -2098,7 +2098,7 @@ Perl_my_setenv(pTHX_ const char *nam, const char *val)
max++;
tmpenv = (char**)safesysmalloc((max+2) * sizeof(char*));
for (j=0; j<max; j++) { /* copy environment */
const int len = strlen(environ[j]);
const size_t len = strlen(environ[j]);
tmpenv[j] = (char*)safesysmalloc((len+1)*sizeof(char));
Copy(environ[j], tmpenv[j], len+1, char);
}
Expand Down Expand Up @@ -2150,17 +2150,17 @@ Perl_my_setenv(pTHX_ const char *nam, const char *val)
if (environ) /* old glibc can crash with null environ */
(void)unsetenv(nam);
} else {
const int nlen = strlen(nam);
const int vlen = strlen(val);
const size_t nlen = strlen(nam);
const size_t vlen = strlen(val);
char * const new_env =
(char*)safesysmalloc((nlen + vlen + 2) * sizeof(char));
my_setenv_format(new_env, nam, nlen, val, vlen);
(void)putenv(new_env);
}
# else /* ! HAS_UNSETENV */
char *new_env;
const int nlen = strlen(nam);
int vlen;
const size_t nlen = strlen(nam);
size_t vlen;
if (!val) {
val = "";
}
Expand All @@ -2187,8 +2187,8 @@ Perl_my_setenv(pTHX_ const char *nam, const char *val)
{
dVAR;
char *envstr;
const int nlen = strlen(nam);
int vlen;
const size_t nlen = strlen(nam);
size_t vlen;

if (!val) {
val = "";
Expand All @@ -2198,7 +2198,7 @@ Perl_my_setenv(pTHX_ const char *nam, const char *val)
my_setenv_format(envstr, nam, nlen, val, vlen);
(void)PerlEnv_putenv(envstr);
Safefree(envstr);
}
}

#endif /* WIN32 || NETWARE */

Expand Down