Fix a situation where a pointer which should point to dynamically
allocated memory was instead pointed to a static string. A later free() on the value of the pointer was a possible source of reported "warning: pointer to wrong page" messages from cron. Use consistent types in sizeof when malloc'ing memory for the environment. PR: kern/12248, bin/11169, bin/9722
This commit is contained in:
parent
8060760500
commit
8261236de4
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=59727
@ -56,7 +56,7 @@ env_copy(envp)
|
||||
|
||||
for (count = 0; envp[count] != NULL; count++)
|
||||
;
|
||||
p = (char **) malloc((count+1) * sizeof(char *)); /* 1 for the NULL */
|
||||
p = (char **) malloc((count+1) * sizeof(char **)); /* 1 for the NULL */
|
||||
if (p == NULL) {
|
||||
errno = ENOMEM;
|
||||
return NULL;
|
||||
@ -81,6 +81,7 @@ env_set(envp, envstr)
|
||||
{
|
||||
register int count, found;
|
||||
register char **p;
|
||||
char *q;
|
||||
|
||||
/*
|
||||
* count the number of elements, including the null pointer;
|
||||
@ -98,12 +99,14 @@ env_set(envp, envstr)
|
||||
* it exists already, so just free the existing setting,
|
||||
* save our new one there, and return the existing array.
|
||||
*/
|
||||
free(envp[found]);
|
||||
q = envp[found];
|
||||
if ((envp[found] = strdup(envstr)) == NULL) {
|
||||
envp[found] = "";
|
||||
envp[found] = q;
|
||||
/* XXX env_free(envp); */
|
||||
errno = ENOMEM;
|
||||
return NULL;
|
||||
}
|
||||
free(q);
|
||||
return (envp);
|
||||
}
|
||||
|
||||
@ -115,11 +118,13 @@ env_set(envp, envstr)
|
||||
p = (char **) realloc((void *) envp,
|
||||
(unsigned) ((count+1) * sizeof(char **)));
|
||||
if (p == NULL) {
|
||||
/* XXX env_free(envp); */
|
||||
errno = ENOMEM;
|
||||
return NULL;
|
||||
}
|
||||
p[count] = p[count-1];
|
||||
if ((p[count-1] = strdup(envstr)) == NULL) {
|
||||
env_free(p);
|
||||
errno = ENOMEM;
|
||||
return NULL;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user