You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I couldn't stand the compiler warnings any more. :)
The patch removes os.tmpnam() and os.tempnam() from the posix module. It
also updates the docs and tests. TMP_MAX is kept for the tempfile
module. I haven't figured out how to remove the defines from pyconfig.h.
I guess they are always added by autoconf/automake.
Martin, why do we need to keep these when we already have tempfile.py?
I don't see that they solve any particular POSIX compatibility
requirement. And they *are* unsafe. (Admitted, sometimes there's no
alternative -- even tempfile.py still provides unsafe APIs by necessity.)
First, you are right. It's not a compiler but a linker warning.
I don't see the point in keeping the methods. They are dangerous to use,
warned upon for a long time and they have a sane replacement that does a
far better job.
loewis commented on Oct 24, 2007
loewismannequin
Mannequin
More actions
Removing them because there is a replacement already is a better reason
than removing them because they give (bogus) warnings, so I'm -0 now.
As you say, tempfile is not any better from a security point of view in
the cases where tmpnam or tempnam would be used (e.g. if you want a
child process create a file whose name you specify).
Whether the tempfile.py implementation is actually better than the one
in the C library, I cannot tell (hence the -0: I don't know whether
tempfile.py or the C library wrapper should be removed). One issue I
just noticed is that tempfile.mkstemp promise of not inheriting the file
descriptor is bogus in the presence of threads and race conditions.
If the rationale for the patch is to eliminate duplication, then
os.tmpfile should be removed as well.
os.tmpfile() is the only method that has no duplicate in tempfile. I
chose to keep it for this very reason. But you made good point, too.
What do you think about renaming tmpfile to _tmpfile and make it
available from the tempfile module as tempfile.tmpfile()?
I totally agree with your opinion on tmpnam and tempnam. As far as I
know it's impossible to prevent a child process from doing something
harmful. The child must be mature enough to do the right think and open
a file with the correct flags.
The promise of tempfile.mkstemp is also bogus for every OS except
Windows. IIRC only Windows supports O_NOINHERIT.
Let me rephrase the rational for my patch: I want to remove duplicate
code to have just but one implementation to create a temporary file
(name). I want the one implementation be under our control and not
depend on some possible broken or stupid C library like Windows where
tmpnam may create the temporary files in C:\. I want an unified way to
get the TEMP dir independent of the API.
loewis commented on Oct 25, 2007
loewismannequin
Mannequin
More actions
os.tmpfile() is the only method that has no duplicate in tempfile.
Why do you say that? tempfile.mkstemp() does essentially the same
as os.tmpfile().
The promise of tempfile.mkstemp is also bogus for every OS except
Windows. IIRC only Windows supports O_NOINHERIT.
Please read the code. It tries to set the CLOEXEC flag on Unix,
which should work on most systems.
Let me rephrase the rational for my patch: I want to remove duplicate
code to have just but one implementation to create a temporary file
(name). I want the one implementation be under our control and not
depend on some possible broken or stupid C library like Windows where
tmpnam may create the temporary files in C:\. I want an unified way to
get the TEMP dir independent of the API.
As I said, I agree with most of this rationale, except that I'm
uncertain whether it is good to trade a stupid C library for a
stupid Python implementation.
With this rationale, again, I think tmpfile should be removed as
well.
Christian can you revise your patch to also remove os.tmpfile per
Martin's request? Make sure unit tests and docs are fixed too.
I can do that for you. But I still believe that os.tmpfile() works
different than tempfile.mkstemp(). The former returns a file descriptor
of a file w/o directory entry and the later a file in tempfile.tempdir.
I can do that for you. But I still believe that os.tmpfile() works
different than tempfile.mkstemp(). The former returns a file descriptor
of a file w/o directory entry and the later a file in tempfile.tempdir.
True. But tempfile.TemporaryFile() returns a temp file without a name.
Activity
tiran commentedon Oct 23, 2007
I couldn't stand the compiler warnings any more. :)
The patch removes os.tmpnam() and os.tempnam() from the posix module. It
also updates the docs and tests. TMP_MAX is kept for the tempfile
module. I haven't figured out how to remove the defines from pyconfig.h.
I guess they are always added by autoconf/automake.
loewis commentedon Oct 23, 2007
-1. First, they are linker warnings, not compiler warnings (I suppose),
plus they are meaningless in the context of Python.
gvanrossum commentedon Oct 23, 2007
Martin, why do we need to keep these when we already have tempfile.py?
I don't see that they solve any particular POSIX compatibility
requirement. And they *are* unsafe. (Admitted, sometimes there's no
alternative -- even tempfile.py still provides unsafe APIs by necessity.)
tiran commentedon Oct 23, 2007
First, you are right. It's not a compiler but a linker warning.
I don't see the point in keeping the methods. They are dangerous to use,
warned upon for a long time and they have a sane replacement that does a
far better job.
loewis commentedon Oct 24, 2007
Removing them because there is a replacement already is a better reason
than removing them because they give (bogus) warnings, so I'm -0 now.
As you say, tempfile is not any better from a security point of view in
the cases where tmpnam or tempnam would be used (e.g. if you want a
child process create a file whose name you specify).
Whether the tempfile.py implementation is actually better than the one
in the C library, I cannot tell (hence the -0: I don't know whether
tempfile.py or the C library wrapper should be removed). One issue I
just noticed is that tempfile.mkstemp promise of not inheriting the file
descriptor is bogus in the presence of threads and race conditions.
If the rationale for the patch is to eliminate duplication, then
os.tmpfile should be removed as well.
tiran commentedon Oct 25, 2007
os.tmpfile() is the only method that has no duplicate in tempfile. I
chose to keep it for this very reason. But you made good point, too.
What do you think about renaming tmpfile to _tmpfile and make it
available from the tempfile module as tempfile.tmpfile()?
I totally agree with your opinion on tmpnam and tempnam. As far as I
know it's impossible to prevent a child process from doing something
harmful. The child must be mature enough to do the right think and open
a file with the correct flags.
The promise of tempfile.mkstemp is also bogus for every OS except
Windows. IIRC only Windows supports O_NOINHERIT.
Let me rephrase the rational for my patch: I want to remove duplicate
code to have just but one implementation to create a temporary file
(name). I want the one implementation be under our control and not
depend on some possible broken or stupid C library like Windows where
tmpnam may create the temporary files in C:\. I want an unified way to
get the TEMP dir independent of the API.
loewis commentedon Oct 25, 2007
Why do you say that? tempfile.mkstemp() does essentially the same
as os.tmpfile().
Please read the code. It tries to set the CLOEXEC flag on Unix,
which should work on most systems.
As I said, I agree with most of this rationale, except that I'm
uncertain whether it is good to trade a stupid C library for a
stupid Python implementation.
With this rationale, again, I think tmpfile should be removed as
well.
Regards,
Martin
[-]Remove os.tmpnam() and os.tempnam() [patch][/-][+]Remove os.tmpnam() and os.tempnam()[/+]gvanrossum commentedon Oct 25, 2007
Christian can you revise your patch to also remove os.tmpfile per
Martin's request? Make sure unit tests and docs are fixed too.
tiran commentedon Oct 25, 2007
Guido van Rossum wrote:
I can do that for you. But I still believe that os.tmpfile() works
different than tempfile.mkstemp(). The former returns a file descriptor
of a file w/o directory entry and the later a file in tempfile.tempdir.
Christian
gvanrossum commentedon Oct 25, 2007
2007/10/25, Christian Heimes <report@bugs.python.org>:
True. But tempfile.TemporaryFile() returns a temp file without a name.
gvanrossum commentedon Oct 25, 2007
Committed revision 58657.
Thanks!