[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: env
From: |
Jim Meyering |
Subject: |
Re: env |
Date: |
Tue, 20 Feb 2007 16:27:52 +0100 |
Harvey Eneman <address@hidden> wrote:
> I've experienced an issue with the env implementation due to its
> modification of the environ external variable:
>
> /* If no program is specified, print the environment and exit. */
> if (argc <= optind)
> {
> while (*environ)
> puts (*environ++);
> exit (EXIT_SUCCESS);
> }
>
> The difficulty occurs when a LD_PRELOAD shared object uses glib
> functions that rely in the stability of environ.
Thanks for the report and patch.
Which functions are those?
> Is there a rational reason why a local variable is not being used? For
> example:
>
> /* If no program is specified, print the environment and exit. */
> if (argc <= optind)
> {
> char **e = environ;
> while (*e)
> puts (*e++);
> exit (EXIT_SUCCESS);
> }
Here's the likely change:
* src/env.c (main): When invoked with no arguments (i.e. when printing
the environment), use a local variable to iterate through the global
"environ" array, rather than "environ" itself. This is solely to
avoid changing the environment for an LD_PRELOAD-substituted "puts"
or "exit" function. Tiny patch by Harvey Eneman. See
<http://thread.gmane.org/gmane.comp.gnu.coreutils.bugs/9735>.
diff --git a/src/env.c b/src/env.c
index 7283926..f2dc5f1 100644
--- a/src/env.c
+++ b/src/env.c
@@ -189,8 +189,9 @@ main (int argc, char **argv)
/* If no program is specified, print the environment and exit. */
if (argc <= optind)
{
- while (*environ)
- puts (*environ++);
+ char const **e = environ;
+ while (*e)
+ puts (*e++);
exit (EXIT_SUCCESS);
}
- env, Harvey Eneman, 2007/02/20
- Re: env, Philip Rowlands, 2007/02/20
- Re: env,
Jim Meyering <=