On Thu, Nov 27, 2014 at 2:45 AM, Marcel Rodrigues <[email protected]> wrote:
>> getenv() is not readonly.
>
>
> POSIX says that "[t]he application shall ensure that it does not modify the
> string pointed to by the getenv() function." I might be completely wrong but
> my impression is that in practice the libc will just give you a pointer to
> an entry in the environ static array, so if you mess with it, subsequent
> calls to getenv() in the same process with the same argument will be messed.
Fixing like this:
static char **add_MANPATH(char **man_path_list, int *count_mp, char *path)
{
if (path) while (*path) {
char *next_path;
char **path_element;
next_path = strchr(path, ':');
if (next_path) {
if (next_path == path) /* "::"? */
goto next;
*next_path = '\0';
}
/* Do we already have path? */
path_element = man_path_list;
if (path_element) while (*path_element) {
if (strcmp(*path_element, path) == 0)
goto skip;
path_element++;
}
man_path_list = xrealloc_vector(man_path_list, 4, *count_mp);
man_path_list[*count_mp] = xstrdup(path);
(*count_mp)++;
/* man_path_list is NULL terminated */
/* man_path_list[*count_mp] = NULL; - xrealloc_vector did it */
skip:
if (!next_path)
break;
/* "path" may be a result of getenv(), be nice and
don't mangle it */
*next_path = ':';
next:
path = next_path + 1;
}
return man_path_list;
}
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox