GNU bug report logs -
#13070
Use putenv+unsetenv instead of modifying environ directly
Previous Next
Reported by: Paul Eggert <eggert <at> cs.ucla.edu>
Date: Mon, 3 Dec 2012 20:37:01 UTC
Severity: normal
Tags: patch
Done: Paul Eggert <eggert <at> cs.ucla.edu>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 13070 in the body.
You can then email your comments to 13070 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#13070
; Package
emacs
.
(Mon, 03 Dec 2012 20:37:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Paul Eggert <eggert <at> cs.ucla.edu>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Mon, 03 Dec 2012 20:37:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Tags: patch
The attached patch is in response to last week's thread on emacs-devel
<http://lists.gnu.org/archive/html/emacs-devel/2012-11/msg00514.html>.
It's relative to trunk bzr 111078. Tested on Fedora 17. I don't see
any issues related to the Microsoft port but I'm CC:ing this to Eli
and Fabrice just in case, as the original bug seems to be Windows-related.
[setenv.txt (text/plain, attachment)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#13070
; Package
emacs
.
(Tue, 04 Dec 2012 16:49:02 GMT)
Full text and
rfc822 format available.
Message #8 received at submit <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Great.
Up to now, it seems to run ok. Provided I added some unsetenv() function
for w32.
(And it is much cleaner that the quick and dirty hack I applied for myself.)
Thanks,
Fabrice
2012/12/3 Paul Eggert <eggert <at> cs.ucla.edu>
> Tags: patch
>
> The attached patch is in response to last week's thread on emacs-devel
> <http://lists.gnu.org/archive/html/emacs-devel/2012-11/msg00514.html>.
> It's relative to trunk bzr 111078. Tested on Fedora 17. I don't see
> any issues related to the Microsoft port but I'm CC:ing this to Eli
> and Fabrice just in case, as the original bug seems to be Windows-related.
>
[Message part 2 (text/html, inline)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#13070
; Package
emacs
.
(Tue, 04 Dec 2012 17:52:01 GMT)
Full text and
rfc822 format available.
Message #11 received at submit <at> debbugs.gnu.org (full text, mbox):
> From: Fabrice Popineau <fabrice.popineau <at> gmail.com>
> Date: Tue, 4 Dec 2012 14:51:06 +0100
> Cc: bug-gnu-emacs <at> gnu.org, Eli Zaretskii <eliz <at> gnu.org>
>
> Up to now, it seems to run ok. Provided I added some unsetenv() function
> for w32.
If you can show your unsetenv, we can commit it in your name, in
preparation for Paul's commit.
Thanks.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#13070
; Package
emacs
.
(Sat, 08 Dec 2012 04:04:02 GMT)
Full text and
rfc822 format available.
Message #14 received at 13070 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
On 12/04/2012 05:51 AM, Fabrice Popineau wrote:
> Provided I added some unsetenv() function for w32.
Can you just add $(BLD)/unsetenv.$(O) to GNULIBOBJS
in lib/makefile.w32-in, or something like that? No point in
having two implementations of unsetenv.
I've attached a revised patch (sans any change to makefile.w32-in),
relative to trunk bzr 111151.
[setenv.txt (text/plain, attachment)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#13070
; Package
emacs
.
(Sat, 08 Dec 2012 11:44:02 GMT)
Full text and
rfc822 format available.
Message #17 received at 13070 <at> debbugs.gnu.org (full text, mbox):
> Date: Fri, 07 Dec 2012 20:02:33 -0800
> From: Paul Eggert <eggert <at> cs.ucla.edu>
> CC: 13070 <at> debbugs.gnu.org, Eli Zaretskii <eliz <at> gnu.org>
>
> On 12/04/2012 05:51 AM, Fabrice Popineau wrote:
> > Provided I added some unsetenv() function for w32.
>
> Can you just add $(BLD)/unsetenv.$(O) to GNULIBOBJS
> in lib/makefile.w32-in, or something like that? No point in
> having two implementations of unsetenv.
I suspect the gnulib implementation won't work for Windows, for the
same reasons the original code you are replacing didn't: it messes
with the environ block, which is allocated on a heap that is different
from the heap used by Emacs. Even if we don't use the gnulib putenv
implementation, moving pointers in the environ block that belongs to
the Windows runtime library is something I'd like to avoid if
possible.
However, I have just installed in trunk revision 111156 changes that
add to w32.c an implementation of unsetenv, and a wrapper for putenv
that makes it more Posix-compliant. So you can now commit your
changes, and I believe they will work.
> I've attached a revised patch (sans any change to makefile.w32-in),
> relative to trunk bzr 111151.
Thanks.
> +void
> +xputenv (char const *string)
> +{
> + if (putenv ((char *) string) != 0)
> + memory_full (0);
> +}
Shouldn't we refrain from signaling memory_full when errno is EINVAL?
I'd suggest an eassert in that case. memory_full will emit a
misleading diagnostic.
Reply sent
to
Paul Eggert <eggert <at> cs.ucla.edu>
:
You have taken responsibility.
(Sat, 08 Dec 2012 17:22:02 GMT)
Full text and
rfc822 format available.
Notification sent
to
Paul Eggert <eggert <at> cs.ucla.edu>
:
bug acknowledged by developer.
(Sat, 08 Dec 2012 17:22:02 GMT)
Full text and
rfc822 format available.
Message #22 received at 13070-done <at> debbugs.gnu.org (full text, mbox):
On 12/08/2012 03:42 AM, Eli Zaretskii wrote:
> Shouldn't we refrain from signaling memory_full when errno is EINVAL?
> I'd suggest an eassert in that case. memory_full will emit a
> misleading diagnostic.
errno cannot be EINVAL, at least not on a POSIXish host:
all strings are allowed as arguments to putenv.
If Microsoft platforms are different it would
make sense to put in an eassert, in w32.c presumably.
I did see a minor problem in the w32.c implementation of unsetenv:
/* MS docs says an environment variable cannot be longer than 32K. */
if (name_len > 32767)
{
errno = ENOMEM;
return -1;
}
unsetenv should return 0 in that case, not -1, since
the variable cannot possibly be in the environment.
This bug doesn't affect Emacs so it's not a pressing one.
I committed the patch as trunk bzr 111158 and am marking
this bug as fixed.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#13070
; Package
emacs
.
(Sat, 08 Dec 2012 18:33:01 GMT)
Full text and
rfc822 format available.
Message #25 received at 13070 <at> debbugs.gnu.org (full text, mbox):
> Date: Sat, 08 Dec 2012 09:20:57 -0800
> From: Paul Eggert <eggert <at> cs.ucla.edu>
> CC: fabrice.popineau <at> gmail.com, 13070-done <at> debbugs.gnu.org
>
> On 12/08/2012 03:42 AM, Eli Zaretskii wrote:
> > Shouldn't we refrain from signaling memory_full when errno is EINVAL?
> > I'd suggest an eassert in that case. memory_full will emit a
> > misleading diagnostic.
>
> errno cannot be EINVAL, at least not on a POSIXish host:
> all strings are allowed as arguments to putenv.
What about NULL pointers? Or strings without a '='? IMO, it's silly
to rely on unspecified behavior, but suit yourself.
> I did see a minor problem in the w32.c implementation of unsetenv:
>
> /* MS docs says an environment variable cannot be longer than 32K. */
> if (name_len > 32767)
> {
> errno = ENOMEM;
> return -1;
> }
>
> unsetenv should return 0 in that case, not -1, since
> the variable cannot possibly be in the environment.
Right, I fixed that.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#13070
; Package
emacs
.
(Sat, 08 Dec 2012 20:00:02 GMT)
Full text and
rfc822 format available.
Message #28 received at 13070 <at> debbugs.gnu.org (full text, mbox):
On 12/08/2012 10:31 AM, Eli Zaretskii wrote:
> What about NULL pointers?
putenv typically dumps core when passed NULL,
so checking errno afterwards wouldn't help.
> Or strings without a '='?
Typically that's valid; it's equivalent to unsetenv.
So typically, checking errno afterwards wouldn't help.
> it's silly to rely on unspecified behavior
Emacs doesn't rely on unspecified behavior, since it never
passes NULL or '='-less strings to xputenv.
Emacs has many, many places where we could
put easserts, but we don't bother because the disadvantages
of code clutter outweigh any advantages of catching bugs,
and this appears to be one of those places.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Sun, 06 Jan 2013 12:24:04 GMT)
Full text and
rfc822 format available.
This bug report was last modified 12 years and 115 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.